Quick UNIX command to display specific lines in the middle of a file from/to specific word


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Quick UNIX command to display specific lines in the middle of a file from/to specific word
# 1  
Old 08-12-2013
Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question.

I have a log text file.

What unix command to extract line from specific string to another specific string.

Is it something similar to?:

more +/"string" file_name


Thanks
# 2  
Old 08-12-2013
Hello,

your requirement is not clear but still one example is as follows.
Let me know your exact requirement so that we can find out exact way.
Here is an example for same.


let us say a file named check_data_column.

Code:
$ cat check_data_column
1 2 3 4
5 6 7 8
9 10 11 12
$

And we have requirement to fgrep the data between digit 1 to digit 8.
Here is the command to find out text that starts from 1 and ends with 8,
just an example.

Code:
$ awk '/^1/,/8$/' check_data_column



Output wil be as follows.

Code:
1 2 3 4
5 6 7 8




Thanks,
R. Singh
# 3  
Old 08-12-2013
Hello,
bellow expanded description of my problem:

I've following text file:

Code:
2013/08/12 10:00 nondisplayed Text
2013/08/12 10:00 nondisplayed Text
2013/08/12 10:00 nondisplayed Text
2013/08/12 10:00 nondisplayed Text
2013/08/12 10:00 nondisplayed Text
2013/08/12 10:00 nondisplayed Text
2013/08/12 10:00 Text 1
Text 2: something
2013/08/12 10:00 Text 2
Text 3: something
Text 3: something
Text 3: something
Text 3: something
Text 3: something
End of displayed text.
2013/08/12 10:00 nondisplayed Text
2013/08/12 10:00 nondisplayed Text
2013/08/12 10:00 nondisplayed Text

I need to extract all lines from "Text 1" to "End of displayed text.".

On the output I would get:

Code:
Text 1
Text 2: something
2013/08/12 10:00 Text 2
Text 3: something
Text 3: something
Text 3: something
Text 3: something
Text 3: something
End of displayed text.



Thank you for your help.
Regards, AT.
# 4  
Old 08-12-2013
Code:
awk '/Text 1/,/End of displayed text/' filename

# 5  
Old 08-12-2013
It works! Smilie. Thanks for your help. Regards, AT.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find specific lines between two brackets after a word

I have a file whose contents are something like below: node 'sghjknch16' { include vmware include sudo include sssd include hardening include hpom include tidal include tibco-mft-ps include jboss include... (2 Replies)
Discussion started by: proactiveaditya
2 Replies

2. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

3. Shell Programming and Scripting

Deleting lines in a fixed length file where there is a word at specific location

I have a big file having 100 K lines. I have to read each line and see at 356 character position whethere there is a word "W" in it. If it is their then don't delete the line otherwise delete it. There are two lines as one Header and one trailer which should remain same. Can somebody... (5 Replies)
Discussion started by: mohit kanoongo
5 Replies

4. Shell Programming and Scripting

Display specific lines content from the file

Hell, I want to grep certain word from file and display above 2 lines and after two lines. Here is the content of sample file. Mar 14, 2013 12:56:59 AM Agent.Agent SendTo INFO: Connection to server:7041 - Credential Transmit Successesful Mar 14, 2013 8:54:21 AM cgent SendTo WARNING:... (7 Replies)
Discussion started by: balareddy
7 Replies

5. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

6. UNIX Desktop Questions & Answers

Display a specific words from a multiple lines

well, i am so not familiar with this kind of things but i am gonna explain extactly what i am looking for so hopfully someone can figure it out :) i have a command that shows memory usage besides the process name, for example(the command output): 500 kb process_1 600 kb process_2 700 kb... (4 Replies)
Discussion started by: Portabello
4 Replies

7. Shell Programming and Scripting

How to delete all lines before a specific word?

Let's say we have a file containing: alllllsadfsdasdf qwdDDDaassss ccxxcxc#2222 dssSSSSddDDDD D1Sqn2NYOHgTI Hello Alex ssS@3 Ok, and let's say we want to delete all words from D1Sqn2NYOHgTI and back, this means to delete the words (and the lines of them) : alllllsadfsdasdf... (2 Replies)
Discussion started by: hakermania
2 Replies

8. UNIX for Dummies Questions & Answers

unix: extract a specific list of lines from a file

I would like to extract specific lines from a file and output them into another file. Each line in the file has a unique ID, and I have a specific list of IDs (that are not consecutive) that I wish to extract. for example: 1 aaaaaa bbbcb cccccc 2 aaaaaa bbbbb cccccd 3 aaaaaa bbbab... (6 Replies)
Discussion started by: mert2481
6 Replies

9. Shell Programming and Scripting

delete lines containing a specific word in afile

Hi, Please suggest how to write a shell script which delets all the lines containing the word unix in the files supplied as argument in the shell. (4 Replies)
Discussion started by: sireesha9
4 Replies

10. UNIX for Dummies Questions & Answers

how to display specific lines of a specific file

are there any basic commands that can display lines 99 - 101 of the /etc/passwd file? I'm thinking use of head and tail, but I forget what numbers to use and where to put /etc/passwd in the command. (2 Replies)
Discussion started by: raidkridley
2 Replies
Login or Register to Ask a Question