Finding a certain string on each line in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a certain string on each line in a file
# 1  
Old 10-07-2005
Finding a certain string on each line in a file

Hi,

I need a script to get every line from a file where there are less then
17 ; on a line.

Thank's
# 2  
Old 10-07-2005
What does your input file look like ?
# 3  
Old 10-07-2005
Quote:
Originally Posted by vino
What does your input file look like ?

like this

316916164;20030306;D;N;;N;19821027;;0575546109;0575491277;;N;IA9556577;NL0;1;Q;Y;
316916200;20030306;D;O;;N;19750424;;;;;R;3030760293;NL0;2;Q;N;
316916211;20030306;D;O;;N;19801212;;0302100013;;;R;3197406341;NL0;1;Q;N;
316916222;20030306;C;O;;N;;;;0525682150;080104710000
;;;;2;J;N;
316916233;20030306;D;O;;N;19790129;;0654385347;0582449781;;P;N75375270;NL0;2;Q;N;
316916244;20030306;D;O;;N;19820719;;0411641243;;;P;N73012331;NL0;1;Q;N;
316916255;20030306;D;N;;N;19730514;;0263704505;;;P;M12128545;NL0;2;Q;N;
316916266;20030306;D;N;;N;19800424;;003289715898;;;P;M20569307;NL0;1;Q;Y;
# 4  
Old 10-07-2005
Code:
awk -F";" '{ if ( NF < 17 ) print $0 }' input.file

# 5  
Old 10-07-2005
Quote:
Originally Posted by vino
Code:
awk -F";" '{ if ( NF < 17 ) print $0 }' input.file


Great works,
1 question , instead of on the screen i would like the line's in a another file


Thanks
# 6  
Old 10-07-2005
Quote:
Originally Posted by vino
Code:
awk -F";" '{ if ( NF < 17 ) print $0 }' input.file

Redirect it to another file

Code:
awk -F";" '{ if ( NF < 17 ) print $0 }' input.file > output.file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding a string in a file

Hello All, I have a text file, i want to search for a string in it and the string is repeated multiple times in a file i want to get the first occurence of the string in a variable. the content of file is like: I want to grepthe first occurance of "Configuration flow done" and store the... (7 Replies)
Discussion started by: anand2308
7 Replies

2. Shell Programming and Scripting

Help with finding last line of file: if statement depending on that line.

Good morning, My first time actually posting in this forum, though I have used this forum to help with numerous projects. I am trying to figure out why my if statement does not work. I have a file where a line is inputted every 15 seconds. I want this if statement to check what the last line... (3 Replies)
Discussion started by: Shanrunt
3 Replies

3. UNIX for Dummies Questions & Answers

Finding files with a certain name string inside of another file.

Hi, I have a very large file that contains a listing of all files on the system. I need to create a listing from that file of all files that start with the following format: s???_*, whereas the '?' represents characters, so the file name begins with an 's' followed by three other characters and... (4 Replies)
Discussion started by: tes218
4 Replies

4. Shell Programming and Scripting

Reformatting single column text file starting new line when finding particular string

Hi, I have a single colum file and I need to reformat the file so that it creates a new line every time it come to an IP address and the following lines are corresponding rows until it comes to the next IP address. I want to turn this 172.xx.xx.xx gwpusprdrp02_pv seinwnprd03... (7 Replies)
Discussion started by: kieranfoley
7 Replies

5. Shell Programming and Scripting

finding the line number of a particular line in a file

Hi Frnds, I need to find the line number of a particular line in a file and store that line number to a variable. if a file named myfile contains following look at the sun look at the moon look at the star look at the ocean i need to get the line number of the line 'look at the... (3 Replies)
Discussion started by: mvignesh
3 Replies

6. Shell Programming and Scripting

finding the Last String in a Line

Hi, i am looking for a command that can help me find the last Sting in a Line ex.. yyeyrtehhehrerry: change this from to here i want to extract END. (5 Replies)
Discussion started by: Rohit1234
5 Replies

7. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

8. Shell Programming and Scripting

Finding a string in a text file and posting part of the line

What would be the most succinct way of doing this (preferably in 1 line, maybe 2): searching the first 10 characters of every line in a text file for a specific string, and if it was found, print out characters 11-20 of the line on which the string was found. In this case, it's known that there... (13 Replies)
Discussion started by: busdude
13 Replies

9. Shell Programming and Scripting

Need help with finding unique string in log file

Shell script help Here is 3 sample lines from a log file <date> INFO <java.com.blah> abcd:ID= user login <date> DEBUG <java.com.blah> <nlah bla> abcd:ID=123 user login <date> INFO <java.com.blah> abcd:ID=3243 user login I want to find unique "ID" from this log... (3 Replies)
Discussion started by: gubbu
3 Replies

10. UNIX for Advanced & Expert Users

finding a string in a file

hi all.. I dont know how to search for a string in a file.. I have tried doing.. I did google but didnt get effective answers..my code is as follows: int search(char* filename,const char* username,const char* passwd) { int flag=0; unsigned long fsize=0; unsigned long current=0;... (2 Replies)
Discussion started by: Ume1986
2 Replies
Login or Register to Ask a Question