How to Modify a file content in UNIX and sort for only required fields ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Modify a file content in UNIX and sort for only required fields ?
# 1  
Old 12-17-2015
How to Modify a file content in UNIX and sort for only required fields ?

I have the below contents in a file after making the below curl call

Code:
curl ... | grep -E "state|Rno" | paste -sd',\n' | grep "Disconnected" > test 

  "state" : "Disconnected",,  "Rno" : "5554f1d2"
  "state" : "Disconnected",,  "Rno" : "10587563"
  "state" : "Disconnected",,  "Rno" : "be6312f7"


Now my next action is for every Disconnected i want to fetch the respective uuid and use that Rno in another call .

Note : As the Contents of the file depends on the curl call so the No of values of Disconnected may vary evey time .

So my next curl call will be in for loop .
i.e
Code:
for $Rno 
curl .../$Rno


How do i achive this in unix or linux ?
# 2  
Old 12-17-2015
It would have been better had you described your problem in total in your first thread supplying a sample of the input!
Wildly guessing, I'd propose
Code:
curl ... | awk '/state.*Disconnected/ {F = 1} F && /Rno/ {print $NF; F = 0}'

With more detailed info, a tailored solution could be presented...
# 3  
Old 12-17-2015
Let me elaborate the Entire problem i am facing and the desired output that i want here .

Once after making the curl call i will get number of Disconnected status or i may not even get it .

If i get the State as disconnected then i need to use the Value of Rno in the next step , which ur previously mentioned solution does not give me as it will only log the values of Rno .
So what i need is consider if there are three values of Rno logged , then i have to loop each Rno and make the curl call
Code:
curl ... | awk '/state.*DISCONNECTED/ {F = 1} F && /uuid/ {print $NF; F = 0}'
"5554f1d2-6f1b-4e74-9ab2-dfe2c1f16dfd"
"10587563-4181-4c6e-8862-2570093f42de"

Now i want to use these two values sequentially in the next curl call i will be making .
i.e it would be in for loop
Code:
for $Rno
curl .../$Rno

Based on the value of this value from curl cmd i will be getting my final results .
So please suggest me the next step of action .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed, awk or another bash command to modify string with the content of another file

Hello everybody, I would like modify some strings using sed or another command line with the content file. For example: - {fqdn: "server-01" , ip: "server-01"} - {fqdn: "server-02" , ip: "server-02"} - {fqdn: "server-03" , ip: "server-03"} - {fqdn: "server-04" , ip: "server-04"} My... (4 Replies)
Discussion started by: dco
4 Replies

2. Shell Programming and Scripting

Sort a file content using one column

Hello All, I have a file which have content as below. 03/09/2014 10:35 AM 618 Admin\rick pqr_ klm2_pog12_20140309_c.xlsx 03/10/2014 10:35 AM 618 user\test01 mplz_ fgh2_lal12_20140310_c.xlsx 03/17/2014 10:35 AM 618 Admin\vick abc_ xyz2_bc12_20140317_c.xlsx 03/18/2014 ... (2 Replies)
Discussion started by: kumar30213
2 Replies

3. Shell Programming and Scripting

Sort a file content with space

Hello, I need help on. I have a File which stores the information as below. It is space separated file, I want to keep only unique record in file based on file name. Also if you notice sometime filename with space appear in last column like (abc_ xyz1_bc12_20140312_c.xlsx) 03/17/2014 ... (9 Replies)
Discussion started by: kumar30213
9 Replies

4. Shell Programming and Scripting

Script to process file from a directory and grep the required content and print

Hi All, below script reads the perticular files from the directory. Am trying to fetch status and print them in the required format. It needs to read line and search for string "Passed/Failed" and print them under correct sub header. script : BASE_DIR=/tmp/test/REPORT/CollectReport #... (16 Replies)
Discussion started by: Optimus81
16 Replies

5. Shell Programming and Scripting

Want to sort a file using awk & sed to get required output

Hi All, Need Suggestion, Want to sort a file using awk & sed to get required, output as below, such that each LUN shows correct WWPN and FA port Numbers correctly: Required output: 01FB 10000000c97843a2 8C 0 01FB 10000000c96fb279 9C 0 22AF 10000000c97843a2 8C 0 22AF 10000000c975adbd ... (10 Replies)
Discussion started by: aix_admin_007
10 Replies

6. Shell Programming and Scripting

Script to open a saved file and modify the content

I am looking for a script where I need to open a file and modify the data like changing the parameters.Can anyone help me? open a file software.rsp . It already contains following data. parameter = false threads=100 user= demf The above should be changed to paramter=true thread= 133... (3 Replies)
Discussion started by: sriki32
3 Replies

7. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

8. Shell Programming and Scripting

Getting required fields from a text file in UNIX

My data is something like as shown below. Out of this i want the details of alarms (ex: 1947147711,1947147081......) and the fields( ex :sw=tacmwafabb9:shelf=1:slot=5-2:pport=2) Once i have these details separated, i want the count of these excluding the duplicates. What is the best possible way... (7 Replies)
Discussion started by: rdhanek
7 Replies

9. UNIX for Dummies Questions & Answers

Unix sort on multiple fields

Hello. I've read a few threads on how to sort on multiple fields, but I still can't get my file to sort correctly. I have a comma delimited .csv file will over a hundred fields. I want to sort it by field 2, field 62 and then field 61 (integer fields). input looks like this well swap field... (2 Replies)
Discussion started by: happy_cow
2 Replies

10. Shell Programming and Scripting

Need a Help with sort a text file with some fields

Ive got a file called listacdrs with this structure: 01/09/2006 12:13 p.m. 1.046.528 CF0155.DAT 01/09/2006 12:13 p.m. 1.046.528 CF0156.DAT 01/09/2006 12:13 p.m. 1.046.528 CF0157.DAT 01/09/2006 12:13 p.m. 1.046.528 CF0158.DAT 01/09/2006 12:14 p.m. ... (3 Replies)
Discussion started by: alexcol
3 Replies
Login or Register to Ask a Question