Script solution as singleline ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script solution as singleline ?
# 1  
Old 04-21-2016
Script solution as singleline ?

Hello

My script has following line and output
Code:
find path -type d | awk -F "/" 'NF == 4{print $3}'
path/custype=Type1/logdate=20160414
path/custype=Type11122/logdate=20160414

But I need following output that I need custtype information between "" like
Code:
path/custype="Type1"/logdate=20160414
path/custype="Type11122"/logdate=20160414

There is no constant value length for custtype.
So is there any solution within awk/sed or any command?

Thanks
# 2  
Old 04-21-2016
With that awk script the output cannot possibly be what you posted. I assumed it was the output of the find command without the awk bit...

Try:
Code:
sed 's|custype=\([^/]*\)/|custype="\1"=|'

# 3  
Old 04-21-2016
Hello msuluhan,

Could you please try following and let me know if this helps you, as I don't have your find command's output so I couldn't test it.
Code:
find path -type d | awk -vs1="\"" -F "/" 'NF == 4{gsub(/custype=/,"custype=" s1,$0);gsub("/logdate",s1"/logdate",$0);print $3}'

Thanks,
R. Singh
# 4  
Old 04-21-2016
Quote:
Originally Posted by RavinderSingh13
Hello msuluhan,

Could you please try following and let me know if this helps you, as I don't have your find command's output so I couldn't test it.
Code:
find path -type d | awk -vs1="\"" -F "/" 'NF == 4{gsub(/custype=/,"custype=" s1,$0);gsub("/logdate",s1"/logdate",$0);print $3}'

Thanks,
R. Singh
Hello

Thanks for your reply, here is the output

Code:
$find 20160415/custstat -type d | awk -vs1="\"" -F "/" 'NF == 4{gsub(/custype=/,"custype=" s1,$0);gsub("/logdate",s1"/logdate",$0);print $3}'
custtype=1234567"
custtype=Type111112"


------------------------------------------------------------------------

Hello Scrutinizer

I tried your advice like following line if I understand correctly

Code:
find 20160415/custstat -type d | sed 's|custype=\([^/]*\)/|custype="\1"=|'

sed does not change any output, output like

Code:
20160415/custstat
20160415/custstat/custtype=1234567
20160415/custstat/custtype=1234567/logdate=20160415
20160415/custstat/custtype=Type111112
20160415/custstat/custtype=Type111112/logdate=20160415

Thanks
# 5  
Old 04-21-2016
Yes in the original sample it was custype and there was always a trailing slash..

Try this instead..
Code:
sed 's|custtype=\([^/]*\)|custtype="\1"|'


Last edited by Scrutinizer; 04-21-2016 at 02:13 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Singleline to Multilines

Hi All, Could you please help to get the below output: Input: J1,ELLA_1,ISDR,JJK,TRS J2,ROSTER,JACK J3,HUP ... ... ... Output: J1,ELLA_1 J1,ISDR J1,JJK J1,TRS (3 Replies)
Discussion started by: unme
3 Replies

2. Shell Programming and Scripting

Perl script solution

Hi I need to do this thing in awk (or perl?). I try to find out how can I identify 1st and 2nd result from the OR expression in gensub: block='title Sata Mandriva kernel /boot/vmlinuz initrd /boot/initrd.img' echo "$block" | awk '{ x=gensub(/(kernel|initrd) /,"\\1XXX","g"); print x }' ... (12 Replies)
Discussion started by: webhope
12 Replies

3. Shell Programming and Scripting

Merge multiline into Singleline

Hi, I'm newbie in this forum and I already searched regarding Merge multiline into singleline but I always found different result which is I don't want it like i want. Here is the data that i have it: *** ALARM 711 A1/BTS "MAD08B1 08ACPA0"U 090604 1040 RADIO X-CEIVER ADMINISTRATION BTS... (5 Replies)
Discussion started by: inteliduy
5 Replies

4. UNIX for Dummies Questions & Answers

How to get the script corrected to get the solution

Can anyone help it out, My Requirement: Actually i grep for the items in the atrblist (Result of it will provide the line where the item present and also the next line of where it presents)then it will be stored in $i.txt From tat result i wil grep 2nd word after getdate() word and store... (2 Replies)
Discussion started by: prsam
2 Replies

5. Shell Programming and Scripting

Please suggest a script or solution?

I have to solve a programming problem for my wife who is engaged in Research in Breast Cancer. 1. She has frequently to search a long single line of alphabetic characters (lower case) for an exact match of a string. e.g.... (4 Replies)
Discussion started by: nmsinghe
4 Replies
Login or Register to Ask a Question