Break a single URL line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Break a single URL line
# 1  
Old 08-02-2016
Break a single URL line

I have a single line below in a file, i can have multiple also
Code:
<java.net.URL>http://server:port/abcd/MaintainRequest.do?operation=121&amp;requestId=123456789&amp;subrequestId=123654789</java.net.URL>

I want below to get below output

Code:
http://server:port/abcd    subrequestId=123654789

I am trying using cut comand but it is not working, I am also using awk, put its a single line so it print whole line when I use $1

Last edited by rbatte1; 08-02-2016 at 07:45 AM..
# 2  
Old 08-02-2016
Please show your attempts.
# 3  
Old 08-02-2016
Quote:
Originally Posted by RudiC
Please show your attempts.

Code:
awk '{print $1}' test.txt

Code:
 cut -c17-20 test.txt



Moderator's Comments:
Mod Comment Please start using code tags not icode tags as required by forum rules!

Last edited by RudiC; 08-02-2016 at 07:45 AM.. Reason: corrected icode tags.
# 4  
Old 08-02-2016
Did you consider setting the field separator to something different from the default when using awk (e.g. ";")?

And, why do you cut 4 chars when you need 48?
# 5  
Old 08-02-2016
Quote:
Originally Posted by RudiC
Did you consider setting the field separator to something different from the default when using awk (e.g. ";")?

And, why do you cut 4 chars when you need 48?
I was trying doing that. but cut command give me only one line and my output is at two different places

below awk also gave me single line in return
Code:
awk '{print $1;}' test

I used
Code:
cut -c17-38 test

to get line from http Smilie


Moderator's Comments:
Mod Comment
Please use CODE tags, not ICODE tags to wrap all code, files, input & output/errors
It makes it easier to read and preserves multiple spaces for indenting or fixed width data.

Last edited by rbatte1; 08-02-2016 at 08:03 AM.. Reason: Convert ICODE tags to CODE tags
# 6  
Old 08-02-2016
... which would yield tp://server:port/abcd/. Do you know what man pages are and are for?

Code:
cut -c15-37,99-121 file
http://server:port/abcd;subrequestId=123654789

is not quite what you seem to need, and it will fail if any of the data changes.

Even
Code:
awk '{gsub (/<[^>]*>/,_);sub (/\/[^\/]*$/, _, $1); print $1, $4}' FS="[?;]" file
http://server:port/abcd subrequestId=123654789

will fail if the input structure changes...

Last edited by RudiC; 08-02-2016 at 08:34 AM..
This User Gave Thanks to RudiC For This Post:
# 7  
Old 08-02-2016
Quote:
Originally Posted by RudiC
... which would yield tp://server:port/abcd/. Do you know what man pages are and are for?

Code:
cut -c15-37,99-121 file
http://server:port/abcd;subrequestId=123654789

is not quite what you seem to need, and it will if any of the data changes.

Even
Code:
awk '{gsub (/<[^>]*>/,_);sub (/\/[^\/]*$/, _, $1); print $1, $4}' FS="[?;]" file
http://server:port/abcd subrequestId=123654789

will fail if the input structure changes...
input will always be same but there will be n number of line.
what you suggest will be better to use

i know what is man and what it for but i didn't know we can use cut command the way you use it, its learning for me.

i learned this
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to break the line to the one above?

Hello everyone! I'm trying to make the below file1 look like file2, can anyone help? Basically I just hit backspace on every line that starts with a number. Thanks! file1: THIS#IS-IT1 4 THIS#IS-IT2 3 THIS#IS-IT3 2 THIS#IS-IT4 1 Result > file2: (4 Replies)
Discussion started by: demmel
4 Replies

2. Shell Programming and Scripting

break from a single list into multiple columns

Hi Guys, I am prety new to the hell scripting world. I am running some grep/cut commands and extracting from a csv file into a list. But the final product I need is that the whole list that I now have has to be broken and separated into columns. Say what I now have extracted is a list of... (6 Replies)
Discussion started by: h_rishi
6 Replies

3. Shell Programming and Scripting

Line Break problem

Hi All, Please can you advise/help on the below issue i did a bcp out of a table, it is having problem of line break such that one line is getting broken in two lines for many records. eg Correct format Line 1: - 000f00000bfe2c2c 000218310300000000GBP GBP 734654 10970.35 ... (3 Replies)
Discussion started by: mad_man12
3 Replies

4. UNIX for Dummies Questions & Answers

VI Line Break?

So I'm in a Unix class and our assignment was to go into VI and write a script to make this file tree. At the end of it, I'd like it to echo "This is the file tree you've created" then a line break, then . But I'm not sure as to who to do it. Is there a way for when I run it (./filesystem), the... (4 Replies)
Discussion started by: bbowers
4 Replies

5. Shell Programming and Scripting

Break single line in 4

How can i break a single line into 5 lines # joseluiz.silvano; Ramal4846; Sala4121; SetorCorregedoria host DF04488962 { hardware ethernet 00:16:41:68:57:0B; fixed-address 10.100.111.245; } INTO # joseluiz.silvano; Ramal4846; Sala4121; SetorCorregedoria host DF04488962 {... (5 Replies)
Discussion started by: danielldf
5 Replies

6. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

7. Shell Programming and Scripting

Add line break for each line in a file

I cannot seem to get this to work.. I have a file which has about 100 lines, and there is no end of line (line break \n) at the end of each line, and this is causing problem when i paste them into an application. the file looks like this this is a test that is a test balblblablblhblbha... (1 Reply)
Discussion started by: fedora
1 Replies

8. Shell Programming and Scripting

BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information. The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

9. Shell Programming and Scripting

Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space. Example of text file; line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none... (7 Replies)
Discussion started by: lewk
7 Replies

10. Shell Programming and Scripting

TO break a line

hi All, Have a doubt in ksh..Am not familiar with arrays but i have tried out a script.. plzzzzz correct me with the script My i/p File is: (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.2.2) (Port = 1525) ) ) (CONNECT_DATA = (SID = TESTDB1) ) ) ... (7 Replies)
Discussion started by: aajan
7 Replies
Login or Register to Ask a Question