Thursday, July 15, 2010

How to wrap longer lines in SQL file...



A post by Aashu Aggarwal...

More i learn UNIX, more i feel its miraculous :)

1. There is a direct way to split the lines in unix. Command is "fold" It can directly split the huge lines into multiple

Syntax>> fold -200 input_file > output_file

This will split all the lines in input_file to lines less than equal to 200 characters. Like say if there is aline with 500 characters, that will be split into 3 lines with 200 character s in 2 lines and 100 in 1 line.

2. If i need to split a line around some character or word then below is the command Syntax >> perl -pe 's/(.{1,199}[,])/\1\n/g' input_file > output_file

In this command will insert newline character after last comma in next 200 characters .{1,199} is telling to see after 200 character [,] is the character to split around. Multiple character can be given like [,:]. It will use both comma and colon to split.
\1\n will copy the result of first part is (.{1,199}[,]) and insert \n after this s/input_pattern/output_pattern/g will replace all such entries in file

I was in love with JAVA, now i love UNIX also.. :)

No comments:

Post a Comment