Would you be able to explain how this works as i cant understand it?
Many thanks
Hello andy391791,
Following may help you in same.
Code:
awk '{gsub("\n[^\n]*/",","); #### gsub, it's an awk's in-built keyword which is used for global substitutions, it's format is gsub(/pattern/string which needs to be replaced/,"new pattern or string which will replace old one",line/variable_name). So here we are giving regex like catch pattern \n to till "/" but we are using *(which is greedy character) to so to tell regex that it should stop till (//myurl/bla/blabla"/"1234) this quoted/bold /(slash) we are giving here [^\n] means till it is not equal to \n in simple language.
So it substitutes from titleA\n//myurl/bla/blabla/1234 to titleA,1234 and so on.
sub(",","\n")} #### using sub here(which same as gsub) only difference is it will only do substitution for very first match of regex, so here (output of above gsub will be like) "titleA,1234,6789" so it will change it to titleA\n1234,6789" (where \n is new line in console it will show on line, I am putting this as \n for understanding purposes.
1' #### awk works on basis of condition and action, so by putting 1 we are telling awk to make condition to TRUE and not mentioning any action here so default action will happen that is printing the line.
RS= ORS='\n\n' file #### Mentioning RS(record separator) and ORS(Output record separator) as newline newline means two new lines continuously, so that lines titleA\nhttp://myurl/bla/blabla/1234\nhttp://myurl/bla/blabla/6789 should be considered as a single record and we could do our above mathematics, mentioning Input_file name too then.
Thanks,
R. Singh
Last edited by RavinderSingh13; 09-08-2016 at 11:06 AM..
Reason: change field to record, Thanks to S for it :)
These 3 Users Gave Thanks to RavinderSingh13 For This Post:
Hi,
I am having problems using grep to extract only 3,4 or 5 digit numbers from a text file, using:
grep '\<\{3,5\}\>' test.txt
or
grep '\{3,5\}' test.txt
or
egrep '{3,5}' test.txt
I would appreciate any help that anyone can give me
thanks (1 Reply)
Hi all,
For a intro UNIX course I'm taking, I need to use the command "tr" to display a file on standard output without any newlines (all on one line).
I assume I would start with "cat filename | tr" but don't know what to put after tr.
Any ideas would be lovely!
Thanks. (3 Replies)
Hi Folks,
I am new to ksh, i have informatica parameter file that i need to update everyday with shell script. i need your help updating this file with new parameters.
sample data
$$TABLE1_DATE=04-27-2011
$$TABLE2_DATE=04-23-2011
$$TABLE3_DATE=03-19-2011
.......Highligned... (4 Replies)
I would like to print string between two sequent digits and concatenate it into one single line.
input.txt
99 cord, rope, strand, twine,
twist, 100 strand, twine, twist,
cord, rope 101 strand, twine,
twist, twine, twist, cord, rope
105 cord, rope ,twi ... (8 Replies)
Hello all! I've looked all over the internet and this site and have come up a loss with an easy way to make a bash script to do what I want to do. I have a file with a naming convention as follows:
2012-01-18 string of words here 123.jpg
2012-01-18 string of words here 1234.jpg
2012-01-18... (2 Replies)
Hi all, I'm quite newbie in shell scripting but I found a problem what I cant solve.
I have a .txt file which looks like this:
/22/
/23/
/24/
and so on and I'd need to make it look like this:
/22/|/23/|/24/|...and so on.
these numbers are growing and has lines like this /2a/ as well.... (15 Replies)
I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file
---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Hello,
This is similar to a previous post, where I was trying to eliminate lines where column #1 is duplicated. If it is a duplicate, the line with the greater value in column #2 should be deleted. In this new case, I need to test duplication with the first three digits in column #1 (ignoring the... (6 Replies)