I have a file that look like this:
I use the following sed script to remove newlines from lines not starting with >
I was trying to use b instead of t. So, this is what I did:
but didnt get the desired result. Is there any way to use b in the second script to eliminate the newlines skipping those ones that start with >?
So, this is what I did:
but didnt get the desired result. Is there any way to use b in the second script to eliminate the newlines skipping those ones that start with >?
The problem does not have anything to do with "t" or "b" but how sed actually works: lets say you have a sed-script like this:#
What happens is this: sed will read in the first line of the input file (this is called the "pattern space"), then apply the first line of its script to it ("command1"), then the next and so on until it reaches the end of the script. If still something is in the pattern space it will be printed to stdout, then the next line of input is read, setting the pattern space to it, then apply the first command ... So, in table format:
Now, what does your code do:
Do you spot it? Once you are inside the condition it is never checked again, you only loop inside it, always adding more text to the pattern space but never doing anything with it - until you hit the last line. Also notice that "/^>/" is true for ANY pattern space content starting with ">". That means, for this:
but also for this, after adding a line:
And the same goes the other way: not "/^>/" is true for this:
but also for this:
This means your logic is wrong, regardless of using "t" or "b". The difference is that "t" will branch only when the last s/...-command actually did something, whereas "b" will branch always. Say, this is the input file:
and this is your sed-script working on the file:
Then the substitution of "yyy" to "YYY" will never take place because ot is unconditionally skipped over. If you change the "b" to a "t" it will be executed because in the lines with no "xxx" the first substitution will do nothing and therefore the "t" will not branch to end.
Dear all,
I face a problem I can not solve: I have different lines in a file and some of them are ending with ie "\r\n" and the others are ending with "\n".
My aim is to supress the string "\r\n" and concatenate that line with the following one.
For example:
Saying I have a file... (4 Replies)
Here is the text that I was to run sed on. In this text I want to insert a semi colon ';' before 'select a13.STORE_TYPE STORE_TYPE,' and after 'from ZZMR00 pa11'
Input text:
insert into ZZMQ01
select pa11.STATE_NBR STATE_NBR,
pa11.STORE_TYPE STORE_TYPE,
... (9 Replies)
hi
i have a requirement to replace a string with another using sed and to get the result newline separated but after sed replacement the newline vanishes
below is sample code
#!/bin/ksh
set -x
string="name sam\nage 45 \nsport soccer"
echo $string
string=`echo $string | sed... (2 Replies)
Hi all,
i am getting count from oracle 11g by spooling it to a file.
Now there are some newline characters and blank spaces i need to remove these.
pl provide me a awk/sed solution.
the spooled file is attached.
i tried this.. but not getting req o/p (6 Replies)
Hi all,
First off, Thank you all for the knowledge I have gleaned from this site!
Deleting Records from a text file... sed paragraphs
The following code works nearly perfect, however each time it is run on the log file it adds a newline at the head of the file, run it 5 times, it'll have 5... (1 Reply)
Hi All,
Please can anyone help me as am deleting a line in a file with the below script:
sed '/"$value"/d' redirects.virgin-atlantic.com.conf > olist
where $value is a variable where the pattern to be matched is stored.
I am not getting any error also but the line containing the pattern... (2 Replies)
FileA
NAME STATE CITY
---- ---- -----
abc ca ca
bcc ny ny
def nj nj
(3 rows affected)
Q1) I want to delete the second row with is ---- ---- -----.
Can delete 2nd row using following
sed '2d' FileA >FileB
but incase the second record is not ---- ---- -----.
then data will... (3 Replies)
Hi everyone,
Since the previous time I received help from unix.com I have been encouraged to learn more.
going through 1 of the articles(View Article) on sed I found, it pointed an interesting situation.
Suppose the text is :
Romeo and Ethel the Dancer Moves Audience to Tears.
I... (3 Replies)
I take the /etc/passwd file and print it out, but I only want the lines that end with sh.
I have
cat /etc/passwd | sed '/sh/!d' Which prints out all lines that have sh somewhere in it.
So I added $, which I thought matches the ends on lines, but its not working, like for example I have have... (5 Replies)
Hi All,
silly question that I'm sure is easy to answer for a more experienced coder...
I have a file called test.txt containing the following text...
need, to, break, this, line, into, individual, lines
using sed, I'd like to make the file look like this...
need
to
break
this
line... (5 Replies)