Modify Column Data using Shell Script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Modify Column Data using Shell Script
# 1  
Old 09-08-2014
Modify Column Data using Shell Script

HI Guys,



Input :-
Code:
P081 wr1 12p0d5: 22.8[dB]
P081 wr1 12p2d18: 23.1[dB]
P149 wr1 1pxcud6/port_0_dev_7: 20.4[dB]
P149 wr1 1pxcud4/port_1_dev_10: 22.4[dB]

Output
Code:
P081 wr1 120 22.8[dB]
P081 wr1 122 23.1[dB]
P149 wr1 10 20.4[dB]
P149 wr1 11 22.4[dB]

In in First two line delete p and after d untill :
In Last two line delete strat from p to "_" [pxcud6/port_] and d to " : "[ _dev_10:]

Last edited by rbatte1; 09-08-2014 at 12:20 PM.. Reason: Split CODE block to better show the two parts
# 2  
Old 09-08-2014
Hello Pareshkp,

Following may help you.

Code:
awk 'NR==1||NR==2{gsub(/p|d.*/,X,$3)} NR==3||NR==4 {gsub(/p.*t\_+/,X,$3);gsub(/\_.*/,Y,$3)} 1'  filename
OR
awk 'NR==1||NR==2{gsub(/p|d.*/,X,$3)} NR==3||NR==4 {gsub(/p.*t\_+|\_.*/,Y,$3)} 1'  filename

Output will be as follows.

Code:
P081 wr1 120 22.8[dB]
P081 wr1 122 23.1[dB]
P149 wr1 10 20.4[dB]
P149 wr1 11 22.4[dB]

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-08-2014 at 11:57 AM.. Reason: Added a little shorter solution
# 3  
Old 09-08-2014
Thanks Man but i have multiple lines with random order

Code:
I want to use if condition >>>

If line have "XCU" then second Option else first option .

# 4  
Old 09-08-2014
Hello pareshkp,

kindly use the following.

Code:
awk '{if($3 !~ /dev/){gsub(/p|d.*/,X,$3)} else {gsub(/p.*t\_+|\_.*/,Y,$3)}} 1'  filename

Output will be as follows.

Code:
P081 wr1 120 22.8[dB]
P081 wr1 122 23.1[dB]
P149 wr1 10 20.4[dB]
P149 wr1 11 22.4[dB]

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 09-08-2014
Super !!!!!!!!!!!!!!!!!!! Solution ........
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

2. Shell Programming and Scripting

How can I modify my script to include or substitute missing data?

Let me start off by saying I am a self taught sometimes scripter so what you will see below won't be pretty. I have created a script to parse through a file with a large amount of data and simply pull out what I need. In doing this I create several files and then paste them together in order to... (2 Replies)
Discussion started by: fsanchez
2 Replies

3. Shell Programming and Scripting

Modify XML tag using shell script

Hi All Need some help with a unix shell script. I have a XML file as shown below: <Root> <Service> <endPoint type="SOAP" protocol="http"> <provider>ABCD</provider> <urlRewrite>/service/xyz/getAccountDetails</urlRewrite> <timeout>30</timeout> </endPoint> </Service> <Service> <endPoint... (3 Replies)
Discussion started by: abhilwa
3 Replies

4. Shell Programming and Scripting

Modify cal command in shell script

Plz help me a) To display on the screen the sorted output of "who" along with the total no. of users. b) the same output (except the no. of users) should be in file FILE1. (2 Replies)
Discussion started by: shivasaini
2 Replies

5. Shell Programming and Scripting

Modify cal command in shell script

Plz help me To modify "cal " command to display calenders of the specified months. $ cal jan....oct (0 Replies)
Discussion started by: shivasaini
0 Replies

6. UNIX for Advanced & Expert Users

Convert column data to row data using shell script

Hi, I want to convert a 3-column data to 3-row data using shell script. Any suggestion in this regard is highly appreciated. Thanks. (4 Replies)
Discussion started by: sktkpl
4 Replies

7. Shell Programming and Scripting

How to modify character to UTF-8 in shell script?

I have a shell script running to load some data from a text file to database. Text file contains some non-ASCII characters like ü. How can i convert these characters to UTF-8 codes before loading to DB. (5 Replies)
Discussion started by: vel4ever
5 Replies

8. Shell Programming and Scripting

Read data from .csv file through shell script & modify

I need to read data from a file called "test.csv" through shell script where the file contains values like name,price,descriptor etc. There are rows where descriptor (& in some rows name) are written as string & other characters like "car_+" OR "bike*" etc where it should contains strings like... (3 Replies)
Discussion started by: raj100
3 Replies

9. Shell Programming and Scripting

how to modify a file using shell script

Hi, i am using SuonOS and ksh. i need to add data into a file(s.txt) using a shell script. i have to pass 3 parameters and these 3 paramaters should add into the file at end of the file. File s.txt is look like, --------------------------------- column1|column2|column3 ... (1 Reply)
Discussion started by: syamkp
1 Replies

10. Shell Programming and Scripting

Is it possible in a shell script to modify itself ??

We are running a quiz and the data collected from the quiz is submitted to the database. My requirement is to write a shell script to get these submitted records. I should be able to run this shell script at any time and the records it returns should be the ones submitted after the script was... (5 Replies)
Discussion started by: sehgalniraj
5 Replies
Login or Register to Ask a Question