Scripting Question - getting lines above ane below certain enteries


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scripting Question - getting lines above ane below certain enteries
# 1  
Old 08-20-2013
Scripting Question - getting lines above ane below certain enteries

Hello -
I have a file in the followig format

Code:
LINE TEXT 1
Line TEXT 2
TIMESTARTED=Fri Aug 16 15:20:23 EDT 2013
START-OF-DATA
123
123444
23232323
END-OF-DATA
Line TEXT 9

I need to get all the lines between the Start of Data and End of Data and pipe it to a file so output should be

Code:
123
12344
2332323


Can you please recommed a command line option that could work
maybe using Awk Sed Grep ?

Thanks

Last edited by Scrutinizer; 08-20-2013 at 04:12 PM.. Reason: code tags
# 2  
Old 08-20-2013
Code:
sed -n '/^START-OF-DATA/,/^END-OF-DATA/{//!p};' file | tee outfile
123
123444
23232323

cat outfile
123
123444
23232323

# 3  
Old 08-20-2013
Code:
sed -n '
    /^START-OF-DATA/,/^END-OF-DATA/{
        /-OF-DATA/d
        w outfile
    }
 ' file

# 4  
Old 08-20-2013
awk
Code:
awk '/START-OF-DATA/{f=1;next} /END-OF-DATA/{f=0} f' file

# 5  
Old 08-20-2013
thank you both -- I will try both and let you know how it goes
Really appreciate it!!
# 6  
Old 08-20-2013
Placing the conditional print (p or p!=0 {print}) after the conditional {p=0} and before the conditional {p=1} saves a next
Code:
awk '/END-OF-DATA/{p=0} p; /START-OF-DATA/{p=1}' file

In general it's more robust to process the end condition only after the start condition was met
Code:
awk 'p&&/END-OF-DATA/{p=0} p; /START-OF-DATA/{p=1}' file


Last edited by MadeInGermany; 08-20-2013 at 10:18 PM..
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Flag duplicate enteries

Morning Unix Guru's, I have written a script which output the contents of a DB. No the DB is not clever to check this or flag and there is no command for the tool to flag this, which human intervention. But i need to check to see if there are duplicate enteries in the file output and flag... (5 Replies)
Discussion started by: Junes
5 Replies

2. Shell Programming and Scripting

Scripting question

Hi I am trying to write a small script which takes one by one file name from a txt file and do a 'll' and need to check if equal to the given month, otherwise it should return back the file name. Note: the file name contains parameter. My code is given below: It is not working .. giving error... (6 Replies)
Discussion started by: Ravindra Swan
6 Replies

3. Shell Programming and Scripting

Scripting question

Preview of command prompt f ---> to start ferret q----> to stop ferret asp@nex:~$ f NOAA/PMEL TMAP FERRET v6.82 Linux 2.6.18-308.8.2.el5PAE 32-bit - 08/03/12 3-Dec-12 16:44 yes? go my.jnl yes?column=4/skip=1/type=num,text ............filename.txt ---... (4 Replies)
Discussion started by: nex_asp
4 Replies

4. Solaris

vfstab enteries automatically added during live upgrade

i am trying to patch a solaris 10 server using live upgrade. issue is, when i create a new BE and activate it during reboot the file system that are mounted but doesnt have an entry in vfstab are automatically added in vfstab of new BE. looks like live upgrade uses df -h output as reference... (0 Replies)
Discussion started by: chidori
0 Replies

5. UNIX for Dummies Questions & Answers

Scripting question

folks; I have a script to remove any files that older than 14 days then move any files that younger than 7 days to another directory. but for some reason it doesn't move the files, when i do it manually it works but not through the script. i tried 2 different ways in writing the move part but it... (6 Replies)
Discussion started by: Katkota
6 Replies

6. UNIX for Advanced & Expert Users

LOST my crontab enteries of root

Hello All, I did very stupid mistake and lost all my crontab enteries on root prompt. Please help me to solve this issue. i did entry on root prompt like this. crontab /home/back.cron and enters but when i enter crontab -l so its only showing 1 entry defined in back.cron and all... (2 Replies)
Discussion started by: wakhan
2 Replies

7. Shell Programming and Scripting

Scripting question

Folks; I'm writing a shell script to extract some fields out of a log file & it will run periodically, how can i make it runs starting from where it left of. for example; if the script will do the extract every 2 days, let's say the first run will extract fields until July 25, 2007 @ 11:15:22... (1 Reply)
Discussion started by: moe2266
1 Replies

8. Shell Programming and Scripting

No. of lines in a file (For scripting)

I'm trying to get the number of lines in a file. I know their are a number of ways of doing this like wc -l or nl which lists the file with the line number. The problem is that I want to use the number of lines a certain program has as a variable in my script. So i can't use wc -l as it returns the... (2 Replies)
Discussion started by: Quesa
2 Replies

9. Shell Programming and Scripting

scripting question

I'm new to shell scripting and am having a problem trying to do something in C shell. I want to write a script that will input something instead of a user doing it. For example, using the command 'write' the user is supposed to type something to be sent to another user. I want a script to be able... (3 Replies)
Discussion started by: batmike
3 Replies

10. UNIX for Dummies Questions & Answers

another scripting question

I am writing a script that will identify the oldest file in a directory. Here's the syntax: #!/bin/ksh cd directory chmod 777 * ls -r -1t > file1 sed -n -e "1P" < file1 > file2 So my problem is, now I have file2, which contains the name of the oldest file in the directory. How do I use,... (1 Reply)
Discussion started by: kristy
1 Replies
Login or Register to Ask a Question