sed one Liner inverse range match-help required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed one Liner inverse range match-help required
# 1  
Old 04-24-2015
sed one Liner inverse range match-help required

Code:
cat test.txt


a



c
d

e


g




Code:
sed '/./,/^$/!d' test.txt 
a

c
d

e

g

Can some body explain how this inverse range match works for this example. i know sed command
Code:
/./,/^$/

means match the first line that contains atleast one character to the first blank line..but getting inverse of it is confusing


Moderator's Comments:
Mod Comment Please have data, examples etc. also enclosed in code tags to preserve indention etc.

Last edited by TomG; 04-24-2015 at 09:15 AM..
# 2  
Old 04-24-2015
Read it like this: From the first non-empty line till the next blank line, DO NOT delete (explicit meaning); for the rest, DELETE (implicit).

Last edited by RudiC; 04-24-2015 at 10:01 AM.. Reason: typo; formulated a bit clearer
This User Gave Thanks to RudiC For This Post:
# 3  
Old 04-24-2015
Can you please explain with contents in test.txt

in the input file
__________________
before 'a' there are 3 blank lines.
before 'c' there are 3 blank lines.
before 'e' there is 1 blank line.
before 'g' there are 2 blank lines.
after 'g' there are 4 blank lines.

output of sed command
__________________________-
before 'a' there is no blank line.
before 'c' there is 1 blank line.
before 'e' there is 1 blank line.
before 'g' there is 1 blank line.
after 'g' there is 1 blank line.

---------- Post updated at 05:55 PM ---------- Previous update was at 05:49 PM ----------

Quote:
Originally Posted by RudiC
Read it like this: From the first non-empty line till the first blank line, DO NOT delete (explixit meaning); for the rest, DELETE (implicit).

Ok man...I understood ..Thank you so much...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get range out using sed or awk, only if given pattern match

Input: START OS:: UNIX Release: xxx Version: xxx END START OS:: LINUX Release: xxx Version: xxx END START OS:: Windows Release: xxx Version: xxx ENDHere i am trying to get all the information between START and END, only if i could match OS Type. I can get all the data between the... (3 Replies)
Discussion started by: Dharmaraja
3 Replies

2. Shell Programming and Scripting

Xargs, awk, match, if greater - as a one-liner

Hi I have multiple files for which I want to use awk for the following: Read each line in each file- if any of the columns match "PVALUE=" followed by the number, then print the line in case the number following "PVALUE=" is greater than 0.05. I did the following: ls *.txt | xargs -I @ -P15... (14 Replies)
Discussion started by: ts89490
14 Replies

3. Programming

Python re.findall inverse Match

I ask of you but yet another simplistic question that I hope can be answered. Its better explained showing my code. Here is my list(tmp_pkglist), which contains a list of all Debian (Jessie) packages: snippet 'zssh (1.5c.debian.1-3.2+b1 , 1.5c.debian.1-3.2 )', 'zsync (0.6.2-1)', 'ztex-bmp... (2 Replies)
Discussion started by: metallica1973
2 Replies

4. Shell Programming and Scripting

sed one liner to Delete blank lines - Help required

Hi, cat test.txt BlankLine BlankLine BlankLine BlankLine ello hi helo BlankLine BlankLine heylo BlankLine BlankLine BlankLine done BlankLine BlankLine BlankLine (1 Reply)
Discussion started by: TomG
1 Replies

5. Shell Programming and Scripting

Match to range in files

I am trying to create a script that will use the position in column A ($1) in 48850.txt and search for it in columns B ($2) in gene.txt. Then when it finds a match it copies the text in column A ($1) and places it in column C ($3) of 48850.txt. I have attached the files. Thank you :). The... (2 Replies)
Discussion started by: cmccabe
2 Replies

6. Shell Programming and Scripting

Perl - quick inverse of a number range

Hello, I'm trying to find an nice solution for the following: 1) I have ranges of numbers (begin-end): 10-15, 20-30, 45-50 2) I have begin limit=0 and end limit=60. 3) I need to find out number ranges between begin limit and end limit that do not overlap with the ranges in item1. In this... (6 Replies)
Discussion started by: pn8830
6 Replies

7. UNIX for Dummies Questions & Answers

Help required on Printing of Numbers, which are missing in the range

Hi Experts, Need help on printing of numbers, which are missing in the range. Pls find the details below Input 1000000002 1000000007 1234007940 1234007946 Output 1000000003 1000000004 1000000005 1000000006 1234007941 (2 Replies)
Discussion started by: krao
2 Replies

8. Shell Programming and Scripting

SED - adding blank line after each Range Match

the following range matching works great but i wish to add a blank line after each range result set... which i've tried and researched to no avail MY INPUT DATA: CURRENT CODE I'M USING: sed -n '/*$/,/;/p' $INPUT_FILE RESULTS I'M GETTING: RESULT I looking to... (5 Replies)
Discussion started by: danmauer
5 Replies

9. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies

10. Shell Programming and Scripting

Match a specific IP range

Hello all, I would like a bit of help with a problem I am having. I have the following example file: $ cat test_hosts 10.10.2.3 host1 10.10.2.4 host2 10.10.2.130 host3 10.10.2.5 host4 10.10.2.230 host5 10.10.2.22 host6 I need to match all IP addresses in the 10.10.2.1-10.10.2.22... (5 Replies)
Discussion started by: sylaan
5 Replies
Login or Register to Ask a Question