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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script to remove all lines from a file before a line starting with pattern
# 1  
Old 03-29-2009
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
now i need the file after executing script to contain lines:
.1.2
d
e
f
# 2  
Old 03-29-2009
Code:
sed -n '/.1.2/,$p' file

or:

Code:
awk '/.1.2/{p=1}p' file

Regards
# 3  
Old 03-29-2009
Good answer. This is because I had started typing an answer while Franklin52 was doing his and mine not as good so having posted it I replaced it with this!

Last edited by TonyFullerMalv; 03-29-2009 at 08:32 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk with sed to combine lines and remove specific odd # pattern from line

In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. UNIX for Beginners Questions & Answers

Grep file starting from pattern matching line

I have a file with a list of references towards the end and want to apply a grep for some string. text .... @unnumbered References @sp 1 @paragraphindent 0 2017. @strong{Chalenski, D.A.}; Wang, K.; Tatanova, Maria; Lopez, Jorge L.; Hatchell, P.; Dutta, P.; @strong{Small airgun... (1 Reply)
Discussion started by: kristinu
1 Replies

3. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

4. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

5. Shell Programming and Scripting

Remove duplicate line starting with a pattern

HI, I have the below input file /* ----------------- cmdsDlyStartFWJ -----------------*/ UNIX_JOB CMDS065J RUN ANY CMDNAME sleep 5 AGENT CMDSHP USER proddata RUN MON,TUE,WED,THU,FRI DELAYSUB 02:00 /* "Triggers daily file watcher jobs" */ ENVAR... (5 Replies)
Discussion started by: varun22486
5 Replies

6. 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

7. 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

8. Shell Programming and Scripting

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, 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... (7 Replies)
Discussion started by: Poonamol
7 Replies

9. Shell Programming and Scripting

Shell script to remove duplicates lines in a file

Hi, I am writing a shell script that needs to remove duplicate lines within a file by category. example: section a a c b a section b a b a c I need to remove the duplicates within th category with out removing the duplicates from the 2 different sections (one of the a's in section... (1 Reply)
Discussion started by: RichElks
1 Replies

10. UNIX for Dummies Questions & Answers

shell script to replace a line contain an unkown pattern starting with "aaa, bbb"

Hello, can any one help me on this? I have a /etc/exports file, it may contain a line (I can not remember exactly). Let me use an a sample file myfile.txt which contains a line * mypattern uncertain key words I want this line (with any possible combination of the uncertain key words to be... (2 Replies)
Discussion started by: Dingrong
2 Replies
Login or Register to Ask a Question