awk to print the string between 3rd and 4th backslashs to end of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to print the string between 3rd and 4th backslashs to end of line
# 1  
Old 09-13-2017
awk to print the string between 3rd and 4th backslashs to end of line

im trying to get

awk to print the string between 3rd and 4th backslashs to end of line

test could be any word

this

Code:
http://example.com/test/ >

to this

Code:
http://example.com/test/ > test

also the other way round insert string at end of line between 3rd and 4th backslashs
thanks
# 2  
Old 09-13-2017
Any attempts / ideas / thoughts from your side?
# 3  
Old 09-13-2017
hi

i know how to print string to end of line like this

Code:
awk '{print $0"append_to_end"}' file > file1

but the string between 3rd and 4th backslashs is ramdom

thats where im stuck

would like to also do it the other way round


appreciate your help thanks
# 4  
Old 09-13-2017
Hello bob123,

Could you please try following and let me know if this helps you.
Code:
sed 's/\(.[^//]*\)\(\/\/\)\(.[^/]*\)\(\/\)\(.[^\/]*\)\(.*\)/\1\2\3\4\5\6 \5/'  Input_file

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 09-13-2017
hi RavinderSingh13,

yeah that works
many thanks

i did close the space between 6 and 5 as i already had a space


Code:
sed 's/\(.[^//]*\)\(\/\/\)\(.[^/]*\)\(\/\)\(.[^\/]*\)\(.*\)/\1\2\3\4\5\6\5/' file

would you know how to do it the other way round

insert the string at the end between 3rd and 4th backslashs
# 6  
Old 09-13-2017
Hello bob123,

Could you please try following and let me know if this helps you.
Code:
awk -F"/" '{print $0,$4}'   Input_file

Thanks,
R. Singh
# 7  
Old 09-13-2017
Quote:
Originally Posted by RavinderSingh13
Hello bob123,

Could you please try following and let me know if this helps you.
Code:
awk -F"/" '{print $0,$4}'   Input_file

Thanks,
R. Singh
hi RavinderSingh13

yeah that works the same as the sed one you posted
thanks

any way to do it the other way round
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

UNIX help to print 50 lines after every 3rd occurrence pattern till end of file

I need help with extract/print lines till stop pattern. This needs to happen after every 3rd occurrence of start pattern and continue till end of file. Consider below is an example of the log file. my start pattern will be every 3rd occurrence of ERROR_FILE_NOT_FOUND and stop pattern will be... (5 Replies)
Discussion started by: NSS
5 Replies

3. Shell Programming and Scripting

awk one liner to print to end of line

Given: 1,2,whatever,a,940,sot how can i print from one particular field to the end of line? awk -F"," '{print $2 - endofline}' the delimiter just happens to be a comma "," in this case. in other cases, it could be hypens: 1---2---whatever---a---940---sot (4 Replies)
Discussion started by: SkySmart
4 Replies

4. Shell Programming and Scripting

1st column,2nd column on first line 3rd,4th on second line ect...

I need to take one column of data and put it into the following format: 1st line,2nd line 3rd line,4th line 5th line,6th line ... Thanks! (6 Replies)
Discussion started by: batcho
6 Replies

5. Shell Programming and Scripting

strange: sed and awk print at end instead of begin of line

Hi! I have a strange behaviour from sed and awk, but I'm not sure, if I'm doing something wrong: I have a list of words, where I want to add the following string at the end of each line: \;\;\;\;0\;1 I try like this: $ cat myfile | awk '{if ( $0 != "" ) print $0"\;\;\;\;0\;1"}' Result:... (5 Replies)
Discussion started by: regisl67
5 Replies

6. Shell Programming and Scripting

awk print last line returns empty string

hello I have a file with lines of info separated with "|" I want to amend the second field of the last line, using AWK my problem is with geting awk to return the last line this is what I am using awk 'END{ print $0 }' myFile but I get an empty result I tried the... (13 Replies)
Discussion started by: TasosARISFC
13 Replies

7. Shell Programming and Scripting

awk print second line after search string

I have multiple config files where I need to pull the ip address from loopback3. The format is the same in every file, the ip is the second line after interface loopback3. interface loopback2 loopback description router ID ip address 192.168.1.1 interface loopback3 loopback description... (3 Replies)
Discussion started by: numele
3 Replies

8. Shell Programming and Scripting

How to extract 3rd line 4th column of a file

Hi, Shell script: I would need help on How to extract 3rd line 4th column of a file with single liner Thanks in advance. (4 Replies)
Discussion started by: krishnamurthig
4 Replies

9. Shell Programming and Scripting

Print starting 3rd line until end of the file.

Hi, I want to Print starting 3rd line until end of the file. Pls let me know the command. Thanks in advance. (1 Reply)
Discussion started by: smc3
1 Replies

10. Shell Programming and Scripting

printing 3rd or 4th feild from last in awk.

Whats up fellas... hope someone can help me with the following... I am parsing an file that is space delimited, however, in the middle, there is an ugly "Account Name" feild that in itself has multiple varying spaces, and commas which throws off my script. The 1st 3 feilds I am able to obtain... (8 Replies)
Discussion started by: djsal
8 Replies
Login or Register to Ask a Question