How to remove particular line from file through shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove particular line from file through shell script?
# 1  
Old 10-12-2010
How to remove particular line from file through shell script?

Hi,

I am pasring a file line by line. I need to check each field in line and remove particular line.

input file lines are,
Code:
02;ABC;PQR
03;aaa;rrr
04;ABC;ggg
09;eee;ABC
04;lmn;stu

I am looking for line containing "ABC" as field value. Now How can I remove this line from input file through ksh script?
thanks in advance.
# 2  
Old 10-12-2010
Can you show us what you've attempted so far?
# 3  
Old 10-12-2010
use sed...

Code:
sed "/ABC/d" inputfile >> outputfile

# 4  
Old 10-12-2010
a grep should be enough for this problem...

Code:
grep -v ABC inputfile > outpufile

# 5  
Old 10-13-2010
Thanks for reply.
I just enhanced my problem that, I need to look for the 4th field of line, If its 1 then I need to remove that line from file.
Input file contents are,
Code:
02;ABC;PQR;1;dfg
03;aaa;rrr;0;fgv
04;ABC;ggg;0fgv
09;eee;ABC;1;asd
04;lmn;stu;1;oik

Code for getting that line,
Code:
while read line
do
Val=`echo $line | cut -d ";" -f 4`
if [ "$Val" -eq 1 ]; then
// remove the line from file
fi
done < $file

Please help me out.

Last edited by Poonamol; 10-13-2010 at 12:59 AM.. Reason: code is added
# 6  
Old 10-13-2010
Code:
$ awk -F\; '$4 != "1" { print }' infile > tempfile
$ mv tempfile infile


Last edited by Chubler_XL; 10-13-2010 at 01:11 AM.. Reason: Typo
# 7  
Old 10-13-2010
Could you please write it in ksh script.
Also let me know the comamnd in brief.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies

2. Shell Programming and Scripting

Remove Space and blank line from file in UNIX shell script

I have below file. I want to remove space at begining of every line and then after also remove blank line from file. I use below code for each operation. sed -e 's/^*//' < check.txt > check1.txt sed '/^\s*$/d' < check1.txt > check2.txt above code not remove all the space... (12 Replies)
Discussion started by: Mohin Jain
12 Replies

3. Shell Programming and Scripting

Remove line breaks in csv file using shell script

Hi All, I've a csv file in which the record is getting break into 1 line or more than one line. I want to combine those splits into one line and remove the unwanted character existing in the record i.e. double quote symbol ("). The line gets break only when the record contains double... (4 Replies)
Discussion started by: rajak.net
4 Replies

4. Shell Programming and Scripting

Shell script to read multiple options from file, line by line

Hi all I have spent half a day trying to create a shell script which reads a configuration file on a line by line basis. The idea of the file is that each will contain server information, such as IP address and various port numbers. The line could also be blank (The file is user created). Here... (1 Reply)
Discussion started by: haggismn
1 Replies

5. Shell Programming and Scripting

useless line feeds in ldapsearch output. Howto remove with shell script?

Hi $ cat ad.sh ldapsearorg -x -LLL -h sb1131z.testbadbigcorp.org -D "CN=ADMINZZ,OU=AdminRoles,DC=testbadbigcorp,DC=org" -w "UT3w4f57lll--4...4" -b "OU=Test,DC=testbadbigcorp,DC=org" "(&(&(&(&(objectCategory=person)(objectClass=user)(lockoutTime:1.2.840.113556.1.4.804:=4294967295)))))" dn$... (3 Replies)
Discussion started by: slashdotweenie
3 Replies

6. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

7. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

8. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

9. Shell Programming and Scripting

shell script to remove all lines from a file before a line starting with pattern

hi,, i hav a file with many lines.i need to remove all lines before a line begginning with a specific pattern from the file because these lines are not required. Can u help me out with either a perl script or shell script example:- if file initially contains lines: a b c d .1.2 d e f... (2 Replies)
Discussion started by: raksha.s
2 Replies

10. Shell Programming and Scripting

How to remove line from crontab in shell script?

Hi folks, I need to write a rollback script which removes the following line from the crontab: 0 0 * * * su - orca -c "/home/orca/core-<SCHEMA_NAME>/cleanup/CLI/cleanup_BRMS.ksh -c OC4J_RiGHTv_<SCHEMA_NAME>" <SCHEMA_NAME> is parameter. How to do it in ksh? Maybe it's better to backup the... (2 Replies)
Discussion started by: nir_s
2 Replies
Login or Register to Ask a Question