Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.
Join 2 lines into 1
Name: pirracas77 Date: January 25, 2007 at 00:47:48 Pacific OS: Solaris 9 CPU/Ram: . Product: .
Comment:
Hello!!! I've just in a old post how to join 2 lines into 1. I need to do similar but I don't know the amount of lines that I must join beforehand.
For example:
TEXT1 123 41 51 TEXT2 12 TEXT3 12 13 14
...and I want that the output like this:
TEXT1 123 41 51 TEXT2 12 TEXT3 12 13 14 ..and so on. Any suggestions?
Name: nails Date: January 25, 2007 at 08:06:12 Pacific
Reply:
A way ....
#!/bin/ksh
# shell match function matchre() { expr "$1" : "$2" >/dev/null 2>&1; }
count=0 while read line do ((count+=1)) if matchre "$line" "TEXT" then if [[ $count -gt 1 ]] then printf "\n%s " "$line" continue fi fi printf "%s " "$line" done < text.file
0
Response Number 2
Name: kokni Date: March 2, 2007 at 15:04:56 Pacific
Reply:
How could the following line
if matchre "$line" "TEXT"
be transformed to match any given combination of 6 digits (my database ids) instead of the string TEXT?
Summary: I'm trying to write a sed script that will switch every 2 lines. For example: Input: Hello there 1 Hello Gerry2 Bye Tim Bye Tim Beans Output would be: Hello Gerry2 Hello there 1 Bye Tim Beans Bye Tim ...
Summary: $!N says to fetch the Next line into the current buffer for the specified range of lines, which in this case is each line that is NOT the last line ($ means last line and ! means NOT). Possibly a clea...
Summary: hello, i'm trying to merge 2 lines using c-shell script... i can't seem to think of a way to get the \n character... can anyone help? example, hello (spaces) world! output: hello world! thanks for ...