LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-13-2013, 04:55 AM   #1
fanatic_ravi
LQ Newbie
 
Registered: Jan 2005
Posts: 22

Rep: Reputation: 0
File Parsing


Any Single one-line command to read file like below and provide o/p as

/dev/sda d6 00 00 CL4Q 03:7e OPEN-V 00000111
/dev/sdaa d6 00 1a CL4Q a3:6e OPEN-V 00000111
/dev/sdaaa 97 03 08 CL3G 0f:83 OPEN-V 00000111
/dev/sdaab 7c 05 27 CL4G 0f:a2 OPEN-V 00000111
/dev/sdaac 97 03 09 CL3G 0f:84 OPEN-V 00000111
/dev/sdaad 7c 05 28 CL4G 0f:a3 OPEN-V 00000111
/dev/sdaae 7c 05 29 CL4G 0f:a4 OPEN-V 00000111


Output should be as below in CAP's


CL4Q 00:03:7E OPEN-V 00000111
CL4Q 00:A3:6E OPEN-V 00000111
CL3G 00:0F:83 OPEN-V 00000111
CL4G 00:0F:A2 OPEN-V 00000111
 
Old 06-13-2013, 05:10 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Code:
awk '{ print $5, "00:" toupper($6), $7, $8 }' infile
BTW: You've been asking a lot of similar questions, you might want to look at the following links:

Bash:
Sed and Awk:
BTW: Please put your script/data inside [code] ... [/code] tags it preserves all spacing. If you don't know how: LQ - BB Code List.

Last edited by druuna; 06-13-2013 at 05:13 AM.
 
Old 06-13-2013, 05:12 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Its a good idea to use code tags https://www.linuxquestions.org/quest...do=bbcode#code when posting data/code to preserve formatting/indentation etc.

Maybe you could amend the code you were given here http://www.linuxquestions.org/questi...le-4175465676/

You could always use awk instead.

Last edited by chrism01; 06-13-2013 at 05:16 AM.
 
Old 06-13-2013, 06:31 AM   #4
fanatic_ravi
LQ Newbie
 
Registered: Jan 2005
Posts: 22

Original Poster
Rep: Reputation: 0
filer parsing

I don't have a linux machine, so downloaded gawk-3.1.6.1 and tried as below and it failed as below .any idea as how to fix this ?
Code:
C:\gawk-3.1.6-1-bin\bin>awk '{ print $5, "00:" toupper($6)
, $7, $8 }' xpinfo.2013_06_02_aft2
awk: '{
awk: ^ invalid char ''' in expression
 
Old 06-13-2013, 06:31 AM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
These are just homework questions.
 
Old 06-13-2013, 06:41 AM   #6
fanatic_ravi
LQ Newbie
 
Registered: Jan 2005
Posts: 22

Original Poster
Rep: Reputation: 0
file Parsing

got the solution
Code:
 awk "{ print $5, \""00:\"" toupper($6), $7, $8 }" xpinfo.2013_06_02_aft2
 
Old 06-13-2013, 06:57 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by fanatic_ravi View Post
I don't have a linux machine
You should include this information in your original posts.

This is a linux forum and answers will be based on that assumption if no indication is there that this is not the case.

Many things are different when using windows
- redirecting is done differently,
- pipes are different,
- EOL is different,
- quoting is different,
- tools used might not have the same functionality/options,
- etc....
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] AWK parsing a CVS file with a seperate list file alexwely Programming 7 03-22-2012 08:51 AM
[SOLVED] Parsing a file? elfoozo Programming 13 03-26-2010 03:25 PM
(Debian) xorg.conf file, (EE) Problem parsing the config file unclerick94 Linux - Newbie 1 07-28-2009 02:27 PM
Reading/Wirting file/parsing xml file using javascript fakhrul Programming 1 08-14-2007 05:08 PM
Need help with file parsing BrianK Programming 2 09-02-2005 05:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration