Sponsored Content
Top Forums Shell Programming and Scripting Please help. How to print number with 'awk'? Post 302417009 by liuzhencc on Wednesday 28th of April 2010 09:07:29 AM
Old 04-28-2010
Please help. How to print number with 'awk'?

Dear all,

I have to transform a bunch of files into a new format. how to do it with bash script, especially with 'awk' command.

the original data
Code:
 O,0,0.2839896442,-1.1628392411,-1.5976515479
 Cr,0,-0.0502858628,-0.1725974837,-0.380627632
 C,0,2.4506658279,-0.476964918,0.2299298249
 C,0,1.6651497007,-1.0345206931,1.1799564362
 H,0,2.7611063963,-1.0380822456,-0.6461973059
 H,0,1.3643870456,-2.0779397457,1.1097563185
 H,0,1.4340863236,-0.5111553249,2.1054910071
 H,0,2.8502644351,0.5285428858,0.3417072936

the new format like this:
Code:
O     0.2839896442   -1.1628392411    -1.5976515479
Cr   -0.0502858628   -0.1725974837    -0.380627632
C     2.4506658279   -0.476964918       0.2299298249
C     1.6651497007   -1.0345206931      1.1799564362
H     2.7611063963   -1.0380822456     -0.6461973059
H     1.3643870456   -2.0779397457      1.1097563185
H     1.4340863236   -0.5111553249      2.1054910071
H     2.8502644351    0.5285428858       0.3417072936

Each column should be aligned exclusively.

Please help me. otherwise, I have to do this work by hand. Smilie

thank you in advance!

zhen
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to print number of lines with awk ?

Can some body tell me how to print number of line from a particular file, with sed. ? Input file format AAAA BBBB CCCC SDFFF DDDD DDDD Command to print line 2 and 3 ? BBBB CCCC And also please tell me how to assign column sum to variable. I user the following command it... (1 Reply)
Discussion started by: maheshsri
1 Replies

2. Shell Programming and Scripting

awk to print exact field number

Hello there. I want some help with awk I have this script that reads a file from awk and you can insert from keyboard any list from the fields that exist so to be printed on monitor echo "give a choice" read -a ans array=${ans} awk -F: -v k="$array" '{ ... (4 Replies)
Discussion started by: covis
4 Replies

3. Shell Programming and Scripting

How do I print out lines with the same number in front using awk?

Hi, I need help in printing out the dates with the largest value in front of it using awk. 436 28/Feb/2008 436 27/Feb/2008 436 20/Feb/2008 422 13/Feb/2008 420 23/Feb/2008 409 21/Feb/2008 402 26/Feb/2008 381 22/Feb/2008 374 24/Feb/2008 360... (7 Replies)
Discussion started by: SIFA
7 Replies

4. Shell Programming and Scripting

awk script: print line number n of another file

Hi, I wrote an awk script to analyse file A. I call the script with files A and B. File A has lines like: 000000033100001 000000036100001 000000039100001 The first 9 characters are interpreted as a line number; for each line number found I want to output this line number of file B. ... (13 Replies)
Discussion started by: kpg
13 Replies

5. Shell Programming and Scripting

awk: print columns depending on their number

hi guys, i have the following problem: i have a matrix with 3 columns and over 450 rows like this: 0.0165 0.0151 0.0230 0.0143 0.0153 0.0134 0.0135 0.0123 0.0195 0.0173 0.0153 0.0182 i now want to calculate the average of every line and divide every element of this... (1 Reply)
Discussion started by: waddle
1 Replies

6. Shell Programming and Scripting

print max number of 2 columns - awk

Is it possible to print max number of 2 columns - awk note: print max if the integer is positive and print min if the integer is negative input a 1 2 b 3 4 c 5 1 d -3 -5 d -5 -3 output a 2 b 4 c 5 d -5 d -5 (4 Replies)
Discussion started by: quincyjones
4 Replies

7. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

8. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

9. Shell Programming and Scripting

awk - Print column number that return value comes from

I have the following awk script that I am using to find the max value in the file and print results. awk 'BEGIN {MAX=-1E100} {for (x=2; x<=NF; x++) if ($x>MAX) {MAX = $x; C1 = $1}} END {print substr(C1,1,11), substr(C1,13,4), substr(C1,18,2), MAX}' ABC* Input (ABC*) ... (6 Replies)
Discussion started by: ncwxpanther
6 Replies

10. UNIX for Beginners Questions & Answers

How to print only number using awk command in Linux ?

Now I'm trying summary sar data. CPU , Memory , Traffic , TPS (Min Max value) CPU is okay using below command. $ sar -p | awk '{gsub(//,"")}1' | awk 'BEGIN {min=1000000; max=0;};\ { if($7<min && $7 != "") min = $7; if($7>max && $7 != "") max = $7; } END {print min, max}' 98.93 99.55 ... (1 Reply)
Discussion started by: tom8254
1 Replies
XMLSTARLET(1)                                                    xmlstarlet Manual                                                   XMLSTARLET(1)

NAME
xmlstarlet - command line XML/XSLT toolkit SYNOPSIS
xmlstarlet [<options>] [<command>] [<cmd-options>] INTRODUCTION
XMLStarlet is a set of command line utilities (tools) which can be used to transform, query, validate, and edit XML documents and files us- ing simple set of shell commands in similar way it is done for plain text files using UNIX grep, sed, awk, diff, patch, join, etc commands. This set of command line utilities can be used by those who deal with many XML documents on UNIX shell command prompt as well as for auto- mated XML processing with shell scripts. OPTIONS
--version Display the version of xmlstarlet. --help Display help. COMMANDS
Type: xmlstarlet <command> --help <ENTER> for command help Available commands include: ed (or edit) Edit/update XML document(s). sel (or select) Select data or query XML document(s) (XPATH, etc). tr (or transform) Transform XML documents(s) using XSLT. val (or validate) Validate XML document(s) (well-formed/DTD/XSD/RelaxNG). fo (or format) Format XML document(s). el (or elements) Display element structure of XML document. c14n (or canonic) XML canonicalization. ls (or list) List directory as XML. esc (or escape) Escape special XML characters. unesc (or unescape) Unescape special XML characters. pyx (or xmln) Convert XML into PYX format (based on ESIS - ISO 8879). p2x (or depyx) Convert PYX into XML. REFERENCES
XMLStarlet is a command line toolkit to query/edit/check/transform XML documents (for more information see http://xmlstar.source- forge.net/). AUTHOR
Mikhail Grushinskiy. XMLSTARLET(1)
All times are GMT -4. The time now is 10:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy