Not at all, because you're right. I've correct the code, if you have any question don't hestitate to ask.
Regards
Thanx and its work. but can u explain me this line:
I know its C conditional and the output pattern but didn't get the meaning. I tried print line by line to see the output. What i got was,
This is a conditional expression operator. The format is : condition ? expression1 : expression2.
If the condition is true, the result is expression1 else the result is expression2.
With our command we check the value of s1 (s1?). If s1 is true (s1 is not empty) we assign the contents of s1, a newline ("\n") and the current record ($0) to s1. If the condition is false (s1 is empty) we assign the current record ($0) to s1.
This is a conditional expression operator. The format is : condition ? expression1 : expression2.
If the condition is true, the result is expression1 else the result is expression2.
With our command we check the value of s1 (s1?). If s1 is true (s1 is not empty) we assign the contents of s1, a newline ("\n") and the current record ($0) to s1. If the condition is false (s1 is empty) we assign the current record ($0) to s1.
Regards
Owh..thank you. you opened my eyes. too many thing is mind, and i didn't realize it. didn't realize "\n" $0 statement is expression1. phewhh.. thanx again.
radoulov/summer_cherry,
Appreciate your feedback but yet to try. Thanx.
Btw, i don't know whether I can post this question here. Seems it related to this swapping, i think i can post it here. Sorry if not.
Let's say I've files named file1, file2, file3 and so on.
Each file contain the same format.
What I'm working now is i'm trying to swap line 2 and line 3 for each file(success with previous code)
but there is condition where the 2nd line must contains specific string, let say: 1012345678. To simplyfy, the string is in column 4.
If 2nd line of the file does not contain the specified string, the script do nothing.
My Algorithm:
Eg input file1:
output:
I have problem to get it right. Hopefully i can get suggestion/advise/solution from you guys.
If linenumber = 2 and field 4 is "1021436587":
1. put the contents of the record to the string s.
2. get the next line.
3. print the line
4. print the previous line
5. get the next record.
The next statement reads the next line and the passes controle back to the first line of the script while the getline function goes further with the next command.
Btw, in the output of your example you've swapped the 1st and the 2nd line.
Hi there,
I have a text that I'm trying to format into something more readable. However, I'm stuck in the last step. I've searched and tried things over the internet with no avail.
OS: Mac
After parsing the original text that I won't put here, I managed to get something like this, but this... (8 Replies)
How can you swap the first 4 line only, the rest will stay the same.
thanks
#!/bin/sh
line=4
awk -v var="$line" 'NR==var {
s=$0
getline;s=$0"\n"s
getline;print;print s
next
}1' fileko.tx
.
desired output: (8 Replies)
Data file example
I look for primary and * to isolate the interesting slot number.
slot=`sed '/^primary$/,/\*/!d' filename | tail -1 | sed s'/*//' | awk '{print $1" "$2}'`
Now I want to get the Touch line for only the associate slot number, in this case, because the asterisk... (2 Replies)
Hi All,
Sorry if this question has been posted elsewhere, but I'm hoping someone can help me! Bit of an AWK newbie here, but I'm learning (slowly!)
I'm trying to cobble a script together that will save me time (is there any other kind?), to swap two fields (one containing whitespace), with... (5 Replies)
Hi
I'm quite new with linux.
Very simple, I need to swap every 2 lines in a file.
Example
INPUT:
a a a
b b b
x x x
y y y
s s s
t t t
OUTPUT:
b b b
a a a
y y y
x x x
t t t (5 Replies)
I have some text:
<date>some_date</date>
<text>some_text</text>
<name>some_name<name>
and I want to transform it to smthng like that:
some_name on some_date: some_text
I've tried sed:
sed 's/<text>\(.*\)<\/text>
<name>\(.*\)<\/name>/\2 - \1/'
but it says unterminated... (13 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
The assignment is to convert a text table to csv format. I've got the cleaning up done, but I need to swap two... (0 Replies)
Hello, I have only recently begun with awk and need to write this:
I have an input consisting of a couple of letters, a space and a number followed by various other characters:
fiRcQ 9( )
klsRo 9( ) pause
fiRcQ 9( ) pause
klsRo continue 1
aPLnJ 62( )
fiRcQ continue 5
... and so on
I... (7 Replies)
I'm a bit new to regex and sed/perl stuff, so I would like to ask for some advice. I have tried several variations of scripts I've found on the net, but can't seem to get them to work out just right.
I have a file with the following information...
# Host 1
host 45583 {
filename... (4 Replies)