How to remove lines containing strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove lines containing strings
# 1  
Old 07-03-2011
How to remove lines containing strings

Hi Guys,

I need some script in removing lines containing strings like ",, ," and "rows". Retain only numbers as the output. See below for the input and output file.


INPUT FILE:
Code:
9817
9832
6285
6312
6313
6318
,,  ,
6329
7078
7098
7130
7959
7983
1253
1254
1257
,,  ,
,rows,selected
,,  ,





DESIRED OUTPUT FILE:
Code:
9817
9832
6285
6312
6313
6318
6329
7078
7098
7130
7959
7983
1253
1254
1257


Thanks in advance.


Br,
Pinpe
# 2  
Old 07-03-2011
Code:
sed '/,,  ,/d;/rows/d' infile > outfile

# 3  
Old 07-03-2011
Code:
awk 'int($1)' file > newfile

# 4  
Old 07-04-2011
one more option with "SED"
Code:
sed -n '/^[0-9]/p' <file_name>


Last edited by Franklin52; 07-04-2011 at 03:22 AM.. Reason: Please use code tags for code and data samples, thank you
# 5  
Old 07-04-2011
Code:
% grep -v "," input_file

# 6  
Old 07-04-2011
Code:
$ grep "^[0-9]\{4\}$" inputfile
9817
9832
6285
6312
6313
6318
6329
7078
7098
7130
7959
7983
1253
1254
1257

# 7  
Old 07-04-2011
Quote:
Originally Posted by jayan_jay
Code:
% grep -v "," input_file

It will leave empty lines behind.

However the humble grep is a strong contender.

Code:
grep '[[:digit:]]' input_file

or little more specific
Code:
grep -E '^[[:digit:]]+$' input_file

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 remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Remove lines containing 2 or more duplicate strings

Within my text file i have several thousand lines of text with some lines containing duplicate strings/words. I would like to entirely remove those lines which contain the duplicate strings. Eg; One and a Two Unix.com is the Best This as a Line Line Example duplicate sentence with the word... (22 Replies)
Discussion started by: martinsmith
22 Replies

3. Shell Programming and Scripting

Compare one files with strings from another + remove lines

Have two files and want to compare the content of file1 with file2. When matched remove the line. awk 'NR==FNR {b; next} !(b in $0)' file1 file2file1 1. if match 2. removefile2 1. this line has to be removed if match 2. this line has a match, remove 3. this line has no match, no removingThe... (3 Replies)
Discussion started by: sdf
3 Replies

4. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

5. Shell Programming and Scripting

How to remove unwanted strings?

Hi Guys, Can someone give me a hand on how I can remove unwanted strings like "<Number>" and "</Number>" and retain only the numbers from the input file below. INPUT FILE: <Number>10050000</Number> <Number>1001340001</Number> <Number>1001750002</Number> <Number>100750003</Number>... (8 Replies)
Discussion started by: pinpe
8 Replies

6. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

7. Shell Programming and Scripting

Grep and delete lines except the lines with strings

Hi I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings. Ex: file name 'test' test: approved package waiting for approval package disapproved package removed package approved... (14 Replies)
Discussion started by: vj8436
14 Replies

8. Shell Programming and Scripting

different take on common ?: search for two strings and remove lines between them

Thank you for assisting, I've got a partial solution just needs a tweak. Hulk-BASH$ cat somefile.txt oh there is some stuff here some more stuff here START_LABEL stuff I want more stuff I want END_LABEL other stuff here too and even more stuff here too Hulk-BASH$ Hulk-BASH$ sed... (8 Replies)
Discussion started by: laser
8 Replies

9. Shell Programming and Scripting

Remove matching lines with list of strings

Hi, HP-UX gxxxxxxxc B.11.23 U ia64 3717505098 unlimited-user license I have a file with below pipe separated field values: xxx|xxx|abcd|xxx|xxx|xx xxx|xxx|abcd#123|xxx|xxx|xx xxx|xxx|abcd#345|xxx|xxx|xx xxx|xxx|pqrs|xxx|xxx|xx xxx|xxx|pqrs#123|xxx|xxx|xx The third field has values like... (6 Replies)
Discussion started by: Nanu_Manju
6 Replies

10. Shell Programming and Scripting

using AWK see the upper lines and lower lines of the strings??

Hi experts, You cool guys already given me the awk script below- awk '/9366109380/,printed==5 { ++printed; print; }' 2008-09-14.0.log Morever, i have one more things- when i awk 9366109380, i can also see the Upper 3 lines as well as below 5 lines of that string. Line 1.... (3 Replies)
Discussion started by: thepurple
3 Replies
Login or Register to Ask a Question