print remaining part from the first-match within a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers print remaining part from the first-match within a file
# 1  
Old 12-23-2008
print remaining part from the first-match within a file

Hi, i was looking for unix command(s) for :

find the first occurrence of a given pattern with in a file and print the remaining part.


below is an example of what i am looking for:

lets say, a file named myfile.txt
Quote:
# more myfile.txt

A
B
C
D
E

#
now, the command i am looking for will do the following

Quote:
# my_command C myfile.txt

C
D
E

#
# 2  
Old 12-23-2008
Hi, If I knew that the number of lines in the source file was limited, I would do it the lazy way,
something like
grep -A9999 C myfile.txt
(meaning: include the 9999 lines following "C" in the output)
but I'm sure someone here soon will supply a solution in sed or awk, it's a common enough question.

/Lakris
# 3  
Old 12-23-2008
Bug

Code:
 sed -n '/C/,${p;}' infile
C
D
E

HTH
# 4  
Old 12-25-2008
Quote:
Originally Posted by Lakris
Hi, If I knew that the number of lines in the source file was limited, I would do it the lazy way,
something like
grep -A9999 C myfile.txt
(meaning: include the 9999 lines following "C" in the output)
but I'm sure someone here soon will supply a solution in sed or awk, it's a common enough question.

/Lakris
thanks.
however, in my case, the grep shows -A as an illegel option.
i m on solaris:

grep: illegal option -- A
Usage: grep -hblcnsviw pattern file . . .
# 5  
Old 12-25-2008
Quote:
Originally Posted by Tytalus
Code:
 sed -n '/C/,${p;}' infile
C
D
E

HTH
thanks a lot ... working fine.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print the specific part of the file name with file creation date?

Hello Folks, I have an requirement, where i need to get total count of the file based on creation date with there filename selected pattern. Filename: MobileProtocol.20171228T154200.157115.udr I want to get the count of files created on each day based on a pattern find. find . -type... (7 Replies)
Discussion started by: sadique.manzar
7 Replies

2. Shell Programming and Scripting

Awk: duplicate column and print remaining as is

Hello there I'd like to make a copy of 2nd column and have it printed in place of column 1. Remaining columns are needed as it. test data: ProbeSet GeneSymbol X22565285 X22566285 ILMN_1050008 MYOCD 6.577 7.395 ILMN_1050014 GPRC6A 6.595 6.668 ILMN_1050017 ... (2 Replies)
Discussion started by: genome
2 Replies

3. Shell Programming and Scripting

Print remaining lines using grep

Hi All, I am having a text file like below ERROR - Not a valid ID : 123 ERROR - Not a valid hello ID : 124 SUCCESS - Valid ID : 12 I need to display like below after reading the file if it finds the error keyword along with displaying this first line when error pattern... (10 Replies)
Discussion started by: rohit_shinez
10 Replies

4. Shell Programming and Scripting

Get remaining line after string match

Want to get the remaining line after pattern match Here it starts - executed commands : - pattern to identify 100:27:500:1:34:END Required output:100:27:500:1:34:END awk '{if(/pattern to identify/) print $2}' < file I have used above code and it not giving... (3 Replies)
Discussion started by: rozee
3 Replies

5. Shell Programming and Scripting

Print particular string in a field of csv file - part 2

Hi, all I need your help and suggestions. I want to print particular strings in a field of a csv file and show them in terminal. Here is an example of the csv file. SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw... (7 Replies)
Discussion started by: refrain
7 Replies

6. UNIX for Advanced & Expert Users

Need a exit from sftp if its ask for password and continue to run remaining part of script.

Hi I am checking status of sftp in Health check script, sftp command is used to connect the server with secure RSA key, which is successfully get connected most of the time but in some case if RSA key ask for password then I need to exit sftp command after few second and continue to run... (1 Reply)
Discussion started by: ketanraut
1 Replies

7. Shell Programming and Scripting

Match and print columns in second file

Hi All, I have to match each row in file 1 with 1st row in file 2 and print the corresponding column from file2. I am trying to use an awk script to do this. For example cat File1 X1 X3 X4 cat File2 ID X1 X2 X3 X4 A 1 6 2 1 B 2 7 3 3 C 3 8 4 1 D 4 9 1 1 (3 Replies)
Discussion started by: newpro
3 Replies

8. Shell Programming and Scripting

print when column match with other file

Hello all, please help. There are two file like this: file1: 1197510.0 294777.7 9666973.0 21.6 1839.8 1197510.0 294777.7 9666973.0 413.2 2075.9 1197510.0 294777.7 9666973.0 689.3 2260.0 ... (1 Reply)
Discussion started by: attila
1 Replies

9. Shell Programming and Scripting

remove values of a file one by one from 2nd file and then print the remaining values of 2nd file

Hi all, I have 2 files. One contains only 1 column and other one contains 2 columns, let say 1_col.txt and 2_col.txt respectively. Here, I will try to explain with an example. Input files : 1_col.txt 2_col.txt a a b x a c p ... (5 Replies)
Discussion started by: AshwaniSharma09
5 Replies

10. Shell Programming and Scripting

print remaining file after a condition is satisfied

Hi , could any one suggest me that how to determine if the first field is numeric and if it is greater than another number then from that point everything else should be printed using awk. I have tried this : awk -v xxxx=$xxxxx ' BEGIN { enable=0 } { print $1 if ( ( $1 !~ "^*$" ... (5 Replies)
Discussion started by: hitmansilentass
5 Replies
Login or Register to Ask a Question