Sponsored Content
Top Forums Shell Programming and Scripting sed: print out to first blank line Post 302268534 by bakunin on Monday 15th of December 2008 08:52:50 PM
Old 12-15-2008
Quote:
Originally Posted by lagagnon
How can I change the sed portion of above to stop at what appears to be a blank line in the text?
I remember searching for a solution to a similar problem some years ago. When i finally found the answer it stunned me because of its simplicity. The trick is to simply quit sed when encountering the line on which you want to stop. Consider the following file:

Code:
# some text
# some text
# some text

# some other text
# some other text

If you want to stop at the blank line (for the purpose of the example we suppose it is completely empty) issue the following sed script:

Code:
sed '/^$/q' infile > outfile

Btw: my problem was to extract "headers" from script files. Usually a script has one or several lines at the beginning that start with a octothorpe ("#"). After these come lines with normal script code and then maybe the one or other commentary line starting with an octothorpe again. I wanted to extract only the first "header" lines, not any commentary after the first noncommentary line. My solution was analogous.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed: delete regex line and next line if blank

Hi, I want to write a sed script which from batiato: batiato/giubbe: pip_b.2.txt pip_b.3.txt pip_b.3mmm.txt bennato: bennato/peterpan: 123.txt consoli: pip_a.12.txt daniele: (2 Replies)
Discussion started by: one71
2 Replies

2. Shell Programming and Scripting

Remove blank line - SED

HI, I have this list of apps like so: DivX Products.app DivX Support.app Uninstall DivX for Mac.app Build Applet.app SpringBoard.app Interface.app MobileAddressBook.app MobileSafari.app MobileSlideShow.app Preferences.app Install Flash Player 8 OSX.app Yap.app check_afp.app ... (10 Replies)
Discussion started by: pcwiz
10 Replies

3. Shell Programming and Scripting

Unix help to find blank lines in a file and print numbers on that line

Hi, I would like to know how to solve one of my problems using expert unix commands. I have a file with occasional blank lines; for example; dertu frthu fghtu frtty frtgy frgtui frgtu ghrye frhutp frjuf I need to edit the file so that the file looks like this; (10 Replies)
Discussion started by: Lucky Ali
10 Replies

4. Shell Programming and Scripting

Print lines after the search string until blank line is found

All I want is to look for the pattern in the file...If I found it at # places... I want print lines after those pattern(line) until I find a blank line. Log EXAMPLE : MT:Exception caught The following Numbers were affected: 1234 2345 2346 Error java.lang.InternalError:... (3 Replies)
Discussion started by: prash184u
3 Replies

5. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line 98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

6. Shell Programming and Scripting

Print lines between a regExp & a blank line

Hi, I have a file, say files_list, as below (o/p of ls -R cmd) $ cat files_list /remote/dir/path/to/file: sub-dir1 sub-dir2 sub-dir3 ... /remote/dir/path/to/file/sub-dir1: remote_file1.csv.tgz <blank line 1> /remote/dir/path/to/file/sub-dir2: remote_file2.csv.tgz <blank... (3 Replies)
Discussion started by: dips_ag
3 Replies

7. Shell Programming and Scripting

awk until blank space and print next line

Hello and Happy New Year 2012! I have this example: 1,2,3 4,5,6 7,8,9 For that, I'm trying to get: 1,2,3 4,5,6 7,8,9 for that, I think this might work but doesnt work so far: awk '{for(i=1;i=NF;i++);sub(/\//,"",$i);print $i}' myfile (2 Replies)
Discussion started by: Gery
2 Replies

8. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

9. Shell Programming and Scripting

sed - How to insert line before the first blank line following a token

Hello. I have a config file (/etc/my_config_file) which may content : # # port for HTTP (descriptions, SOAP, media transfer) traffic port=8200 # network interfaces to serve, comma delimited network_interface=eth0 # set this to the directory you want scanned. # * if have multiple... (6 Replies)
Discussion started by: jcdole
6 Replies

10. Shell Programming and Scripting

awk to print blank line between files

I have an AWK command that goes like this: awk '/from BOITE_AUX_LETTRES/,/end-procedure|END-PROCEDURE|end-select|END-SELECT/ {print FILENAME,FNR,$0}' *prp I get my results as follows: ZKELEXTV2.prp 16 from BOITE_AUX_LETTRES(#num_lettre) ZKELEXTV2.prp 23 LET $CONDEXTR = ' where... (2 Replies)
Discussion started by: mvalonso
2 Replies
weatherrc(5)							File Formats Manual						      weatherrc(5)

NAME
weatherrc - configuration file format for the weather(1) utility DESCRIPTION
The weatherrc file format is intended to specify a set of aliases by which to group URIs for METAR station conditions and alert/forecast zones, but other command-line options and flags for the weather utility can be specified as well. The file is organized as an INI-format config, with the alias name in [] brackets and the associated parameter/value pairs on following lines. Parameters and their values are separated by = or : characters. Multi-word values do not need quoting. These parameters are supported... alert include local alert notices (possible values are False and True or 0 and 1) atypes list of alert notification types to display (ex: tornado_warning,urgent_weather_message) cache control all caching (possible values are False and True or 0 and 1) cache_data control retrieved data caching (possible values are False and True or 0 and 1) cache_search control search result caching (possible values are False and True or 0 and 1) cacheage duration in seconds to refresh cached data (ex: 900) cachedir directory for storing cached searches and data (ex: ~/.weather) conditions output current conditions (possible values are False and True or 0 and 1) defargs list of default command-line arguments (ex: avl,rdu) forecast include a local forecast (possible values are False and True or 0 and 1) headers list of conditions headers to display (ex: temperature,wind) imperial filter/convert conditions for US/UK units (possible values are False and True or 0 and 1) metric filter/convert conditions for metric units (possible values are False and True or 0 and 1) quiet skip preambles and don't indent (possible values are False and True or 0 and 1) setpath directory search path for correlation sets (ex: .:~/.weather) verbose show full decoded feeds (possible values are False and True or 0 and 1) EXAMPLES
The following is an example ~/.weather/weatherrc defining a couple aliases named home and work to be displayed when running the utility with no aliases specified... [default] defargs = home,work [home] description = Conditions and Forecast at Home forecast = True metar = http://weather.noaa.gov/pub/data/observations/metar/decoded/KRDU.TXT zone_forecast = http://weather.noaa.gov/pub/data/forecasts/zone/nc/ncz041.txt [work] description = Conditions at Work metar = http://weather.noaa.gov/pub/data/observations/metar/decoded/KGSO.TXT Now if weather is invoked by itself on the command line, it will output conditions for home and work, and also a forecast for home only. AUTHOR
Specification and manual written by Jeremy Stanley <fungi@yuggoth.org>. SEE ALSO
weather(1) 2.0 2012-06-24 weatherrc(5)
All times are GMT -4. The time now is 05:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy