separate file by line length


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting separate file by line length
# 1  
Old 05-27-2009
separate file by line length

hi all,

i'm new in unix....

i have question, sorry if it's missplace or too silly

let say i have a file name testfile.log that contains data

000001
000002
000003
aaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbb
cccccccccccccc
dddddddddddddddddd
000004

i want to make new file (newfile.log) that only consist

aaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbb
cccccccccccccc
dddddddddddddddddd

ps: what i want is, i split by line length which is > 6

regards,

steven
# 2  
Old 05-27-2009
Quote:
Originally Posted by venven
...
i want to make new file (newfile.log) that only consist

aaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbb
cccccccccccccc
dddddddddddddddddd

ps: what i want is, i split by line length which is > 6

...
Something like this:

Code:
$
$ # display contents of testfile.log
$ cat testfile.log
000001
000002
000003
aaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbb
cccccccccccccc
dddddddddddddddddd
000004
$
$ # pick up only those lines that are more than 6 chars long
$ awk 'length > 6' testfile.log
aaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbb
cccccccccccccc
dddddddddddddddddd
$
$ # pick up only those lines that are more than 6 chars long AND put them in a new file
$ awk 'length > 6' testfile.log > newfile.log
$
$ # verify that the new file has the stuff you want
$ cat newfile.log
aaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbb
cccccccccccccc
dddddddddddddddddd
$
$

tyler_durden
# 3  
Old 05-27-2009
thx

thx help alot

-----Post Update-----

another question

i want to make new file that dont consist particular string for example "bbbb"

i have

aaaaaaa
vbbbbq
abbbbx
cccccc
ddddd


i want to make new file that consist
aaaaaaa
cccccc
ddddd



thx before
# 4  
Old 05-27-2009
you questions are very simple to do. what have you got ? someone has already shown you how to use awk. Look up the awk documentation and see how you can do the second task.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print line is values between two fields in separate file

I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

3. Programming

Read text from file and print each character in separate line

performing this code to read from file and print each character in separate line works well with ASCII encoded text void preprocess_file (FILE *fp) { int cc; for (;;) { cc = getc (fp); if (cc == EOF) break; printf ("%c\n", cc); } } int main(int... (1 Reply)
Discussion started by: khaled79
1 Replies

4. Shell Programming and Scripting

Compare two string in two separate file and delete some line of file

Hi all i want to write program with shell script that able compare two file content and if one of lines of file have # at the first of string or nothing find same string in one of two file . remove the line in second file that have not the string in first file. for example: file... (2 Replies)
Discussion started by: saleh67
2 Replies

5. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (1 Reply)
Discussion started by: erlanq
1 Replies

6. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (2 Replies)
Discussion started by: erlanq
2 Replies

7. Shell Programming and Scripting

How to separate file to multiple line.

Hi Unix gurus, I am facing a problme with file. I need separate my file into multiple line. eg. Soure file: PRT07, aaa, bbb, 46, PRT06, ccc, ddd, 57, PRT05, eee,fff,aa, target file: PRT07, aaa, bbb, 46 PRT06, ccc, ddd, 57 PRT05, eee,fff,aa :wall: thanks in advance (4 Replies)
Discussion started by: ken002
4 Replies

8. Shell Programming and Scripting

Read 1-line file and separate into multiple variables

I have one line files with 17 records separated by a semi-colon. I need to create a variable from each record, which I can do via a separate awk for each one, but I know there has to be a better way. Along with pulling out the variable, I need to convert some url coding like a + to a space, etc.... (4 Replies)
Discussion started by: numele
4 Replies

9. UNIX for Advanced & Expert Users

Fixing line length in a file

I have a file containing many lines all with varying lengths. I need each line in the file to be 100 characters in width but I can not find a way of doing this. I want to append to each line spaces to bring the width of the line to 100 but I need a generic way to work out how many spaces I need. ... (2 Replies)
Discussion started by: dbessell
2 Replies

10. UNIX for Dummies Questions & Answers

Listing words from a file on a Separate Line

Hi, I want to list all the words in my file on a separate line. I am using the bourne(sh)/bourne again shell(bash). Thanks, theA (2 Replies)
Discussion started by: Astudent
2 Replies
Login or Register to Ask a Question