awk, sed, perl assistance in outputting formatted file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk, sed, perl assistance in outputting formatted file
# 8  
Old 11-27-2009
i think u can use only printf :-) no fancy commands
Code:
printf %s%s"\n" $(cat filename)

# 9  
Old 11-28-2009
Here's one way to do it with Perl:

Code:
$
$ cat f4
ACTASS=
802
BASECOS=
279
COSNCHG=
3
CUSCOS=
52
UPLDCOS=
2
$
$ perl -lne '/=$/ ? printf : print' f4
ACTASS=802
BASECOS=279
COSNCHG=3
CUSCOS=52
UPLDCOS=2
$
$

And a tad shorter:

Code:
perl -lnE '/=$/ ? printf : say' f4

Or:

Code:
perl -lne 'BEGIN{undef $/} s/=\n/=/g; print' f4

Code:
perl -lne '$.%2==1 ? printf : print' f4

tyler_durden

Last edited by durden_tyler; 11-28-2009 at 01:06 AM..
# 10  
Old 11-28-2009
Quote:
Originally Posted by vidyadhar85
i think u can use only printf :-) no fancy commands
Code:
printf %s%s"\n" $(cat filename)

Smilie
Code:
printf %s%s"\n"  $(< file)

My bash can do that , no UUoC Smilie
# 11  
Old 11-28-2009
Quote:
Originally Posted by danmero
Smilie
My bash can do that , no UUoC Smilie
And so can ksh and zsh, posix can't though.
# 12  
Old 11-28-2009
Code:
xargs -n2 < urfile

# 13  
Old 11-28-2009
Code:
xargs -n2 < urfile | tr -d ' '

# 14  
Old 11-28-2009
[solved]

Thanks guys,

I now have to spend the rest of the weekend learning all your great code.

Thanks again to all who assisted.

Abacus
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Processing a formatted file with awk

Hi - I want to interrogate information about my poker hands, sessions are all recorded in a text file in a particular format. Each hand starts with the string <PokerStars> followed by a unique hand reference and other data like date/time. There is then all the information about each hand. My first... (5 Replies)
Discussion started by: rbeech23
5 Replies

2. Shell Programming and Scripting

awk operation to get table formatted file

I need to parse .conf file in Unix system to get output from the snippets like below : ; generated by mod_identity exten => int,1,GoSub(mdc_template-3,s,1) exten => int,n(next_380),Return() ; default action for busy exten => ext,1,GoSub(mdc_template-3,s,1) exten => ext,n,Set(PRI_CAUSE=17)... (2 Replies)
Discussion started by: cheecky
2 Replies

3. Shell Programming and Scripting

Modify the file with awk,sed or perl

Hi All, I need help from any of you.Would be so thankful for your help. I/P DDDD,1045,161,1557,429,1694,800,1911,1113,2460,1457,2917> 1609,3113,1869,3317,2732,3701,3727,4132,5857,5107> 9004,6496 DDDD,1125,157,1558,429,1694,800,1911,1117,2432,1444,2906>... (2 Replies)
Discussion started by: Indra2011
2 Replies

4. Shell Programming and Scripting

awk, sed or perl regexp to print values from file

Hello all According to the following file (orignal one contains 200x times the same structure...) I was wondering if someone could help me to print <byte>??</byte> values example, running this script/command like ./script.sh xxapp I would expect as output: 102 116 112 ./script.sh xxapp2... (2 Replies)
Discussion started by: cabrao
2 Replies

5. Shell Programming and Scripting

Using sed (or awk or perl) to delete rows in a file

I have a Unix file with 200,000 records, and need to remove all records from the file that have the character ‘I' in position 68 (68 bytes from the left). I have searched for similar problems and it appears that it would be possible with sed, awk or perl but I do not know enough about any of these... (7 Replies)
Discussion started by: joddo
7 Replies

6. Shell Programming and Scripting

reformatting xml file, sed or awk I think (possibly perl)

I have some xml files that cannot be read using a standard parser, or I am using the wrong parser. The issues seems to be spaces in some of the tags. Here is a sample,<UgUn 2 > <Un> -0.426753 </Un> </UgUn>The parser isn't able to find the number 2, so that information is lost, etc. It seems... (16 Replies)
Discussion started by: LMHmedchem
16 Replies

7. Shell Programming and Scripting

Script Assistance - Outputting to file with Awk

I'm trying to take a list of domains, find out the MX resolve it to IP then find out what the NS is and output the contents to a new file. The only problem i'm having is when checking the Ip or host of the MX i can only get it to print the column with the MX record and the results of the host... (1 Reply)
Discussion started by: spartan22
1 Replies

8. Programming

Perl GD::Graph and outputting to a graphics file

To successfully export a perl GD::Graph object to a graphics file (e.g. a .png file), do you do the following ? # Set graph data $graph->set(....); $graph->plot(\@graph_data); open(IMG,'>file.png') or die $!; binmode IMG; print IMG $graph->png; close IMG; Reason Im asking is... (1 Reply)
Discussion started by: JamesGoh
1 Replies

9. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies

10. Shell Programming and Scripting

sed not outputting last line of input file

I am using sed for a simple substitution (see command syntax below). Everything works fine except that the last line of the input file does not get written to the output file. Has anyone ever seen this and know of way to force the last line to be written? I don't know if it's playing a part in... (3 Replies)
Discussion started by: 2reperry
3 Replies
Login or Register to Ask a Question