How to extract more than 1 line in a textfile ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract more than 1 line in a textfile ?
# 1  
Old 06-21-2010
How to extract more than 1 line in a textfile ?

Hi, I'm starting a little project with a shell script but I'm don't know how to do it. Maybe someone can help me.

I have un text file like this :

Quote:
@BEFORE@
nothing
@ADDLINE1@
M. Duran Stephan
@ADDLINE2@
21 Falcon av,
@ADDLINE3@
1211
@ADDLINE4@
Geneva
@OTHER@
blabla
I'd like to do a script who will extract from my file from @ADDLINE1@ to @ADDLINE4@ only and I have no idea how to do this.

Any idea ?

Thanks
# 2  
Old 06-21-2010
If your' input is static , then :

Code:
 
awk '/@ADDLINE1@/,/@ADDLINE4@/' input_file

# 3  
Old 06-21-2010
Code:
sed -n '/BEFORE/,/ADDLINE/p'  inputfile


Last edited by Scott; 06-21-2010 at 08:10 AM..
# 4  
Old 06-21-2010
I think Panyam meant to use sed, that isn't awk syntax.

Code:
sed  -n '/@ADDLINE1@/,/@ADDLINE4@/p'  file

# 5  
Old 06-21-2010
Hi Jim,

Not sure , why you thought it's not an awk one Smilie

Code:
 
TES>awk '/@ADDLINE1@/,/@ADDLINE4@/'  input_file
@ADDLINE1@
M. Duran Stephan
@ADDLINE2@
21 Falcon av,
@ADDLINE3@
1211
@ADDLINE4@
TES>sed -n '/@ADDLINE1@/,/@ADDLINE4@/p' input_file
@ADDLINE1@
M. Duran Stephan
@ADDLINE2@
21 Falcon av,
@ADDLINE3@
1211
@ADDLINE4@

# 6  
Old 06-21-2010
thanks you guys, exactly what I need Smilie

I have another question, with this command I want to append multiples text files results to a file, but it doesn't work.

I've try something like this :

Quote:
ls -l *.txt | awk '/@ADDLINE1@,@ADDLINE8@/' > result.txt
# 7  
Old 06-21-2010
Try:
Code:
awk '/@ADDLINE1@,@ADDLINE8@/' *.txt > result.txt

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 separate sorte different characters from one textfile and copy them in a new textfile?

My first post, so don't kill me :) Say i open some textfile with some example like this. on the table are handy, bread and wine Now i know exactly what is in and i want to separate and sorted it in terminal to an existing file with another 2 existing lines in like this: table plane ... (3 Replies)
Discussion started by: schwatter
3 Replies

2. Shell Programming and Scripting

awk print in one line after reading textfile with paragraphs

Hello everybody I have a text file which has the following format: nmm "text20140601.033954text" "text" "text" "text" , ... , "text" "text" , ... , Lat 36.3247 Lon 16.0588 Depth 8 "text", ... , "text" "text", ..., CovXX 1.65 CovYY 2.32 CovZZ 1.2 "text" , ..., "text nmm ... (6 Replies)
Discussion started by: phaethon
6 Replies

3. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

4. Shell Programming and Scripting

Extract Line and Column from CSV Line in ksh or bash format

Hi, I was doing some research and can't seem to find anything. I'm trying to automate a process by creating a script to read a csv line and column and assigning that value to a variable for the script to process it. Also if you could tell me the line and column if it's on another work ... (3 Replies)
Discussion started by: vpundit
3 Replies

5. Shell Programming and Scripting

Write $line number into textfile and read from line number

Hello everyone, I don't really know anything about scripting, but I have to manage to make this script, out of necessity. #!/bin/bash while read -r line; do #I'm reading from a big wordlist instructions using $line done Is there a way to automatically write the $line number the script... (4 Replies)
Discussion started by: bobylapointe
4 Replies

6. UNIX for Dummies Questions & Answers

Script to add text before the first word on a line in a textfile.

How can i make a script to add text before the first word on a line in a textfile : Example: Old line: is my place New line: this is my place Please use and tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks. (3 Replies)
Discussion started by: mjanssen
3 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

Get line of textfile and store it in variable

Hi! I need to do the following: (1) I wan't to extract a line of a textfile (defined by a numer) and store it into a variable... (2) ...but I want to cut out a part of the line which is between two tokens and store just this to the variable Example: BlaBlaBla Bla2Bla2Bla2 *pPointerOne;... (4 Replies)
Discussion started by: Michi21609
4 Replies

9. Shell Programming and Scripting

4 GB delimited-textfile on ONE LINE

I have delimited-text files ( > 4GB ) and is just one line. OS: HP-UX 11.23 Awk / cut / sed all have line_max limitations. & unable to read one line in (Buffered-mode). Sample file: xxxx|adsfadf|Afdsa|adsf|afds|Asdfas|ads|Afds|Asdf| .....till forever, I want to put a carriage... (5 Replies)
Discussion started by: magedfawzy
5 Replies

10. Shell Programming and Scripting

cut a string in a textfile line per line

i need to cut the string in a textfile but each line has a specific way of cutting it (different lengths) i have a for loop that gets the string line per line, then each line has to be compared: for x in `cat tmp2.txt`; do if; then echo 'BAC' elif ... (6 Replies)
Discussion started by: izuma
6 Replies
Login or Register to Ask a Question