Sponsored Content
Top Forums Shell Programming and Scripting Curious question? How to put a string into two columns. Post 302369001 by liuzhencc on Friday 6th of November 2009 07:34:30 AM
Old 11-06-2009
Quote:
Originally Posted by scottn
Code:
awk -F= '
  /.log/ && P { print "" }
  /.log/ { P=1 }
  /^HF/ { printf $2 " "; getline; print $2; P=0 }
' file1

-240.451527 -240.5213996
-240.451527 -240.5213996
-240.4273718 -240.4956636
-240.4515273 -240.5214005


-319.0829339 -319.177099

Perfect! It works. But I was so confused with this powerful script.
How did you put these empty lines?
Could you explain me something about this script.
I really want to learn something from here.
Thank you very much!

Very strange thing took place! see the following lines
Code:
1c1
< awk -F= '/.log/ && P { print "" }/.log/ { P=1 }/^HF/ { printf $2 "           " ; getline; print $2; P=0 }' TE.txt >> test7
---
> awk -F= '/.log/ && P { print "" }/.log/ { P=1 }/^HF/ { printf $2 "           " ; getline; print $2; p=0 }' TE.txt >> test7

I thought they are exactly the same code. But the outputs are totally different. The first line gave the correct output but the second line didn't.
Why? It's so strange that I cannot understand.
Output with the code of the first line
Code:
-240.451527           -240.5213996
-240.451527           -240.5213996
-240.4273718           -240.4956636
-240.4515273           -240.5214005


-319.0829339           -319.177099
-319.082436           -319.1777128
-319.0857963           -319.1786906
-319.0814125           -319.174904

-319.0814044           -319.1748736
-319.0827201           -319.173826
-319.0863378           -319.1788978
-319.075422           -319.1668696
-319.0650245           -319.1607778
-319.103556           -319.1942108

Output with the second line of the code.
Code:
-240.451527           -240.5213996

-240.451527           -240.5213996

-240.4273718           -240.4956636

-240.4515273           -240.5214005



-319.0829339           -319.177099

-319.082436           -319.1777128

-319.0857963           -319.1786906

-319.0814125           -319.174904


-319.0814044           -319.1748736

-319.0827201           -319.173826

-319.0863378           -319.1788978

-319.075422           -319.1668696

-319.0650245           -319.1607778

-319.103556           -319.1942108


-319.103556           -319.1942133


Last edited by liuzhencc; 11-06-2009 at 09:09 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

put a string before a searched string

hi all! i have a working that looks like this... file1 MALE JOHN MALE ANJO FEMALE ANNE MALE JAMES FEMALE HONEY FEMALE IZA what i want to do is insert "M" when the first string is "MALE" and insert "F" when the first string is "FEMALE". file1 M MALE ... (10 Replies)
Discussion started by: kingpeejay
10 Replies

2. Shell Programming and Scripting

Curious cron job question

Wow that was annoying, I wrote a huge long entire post out, clicked submit and the damn thing lost my entire post. Ok, here's what I am needing to do. Have a cron job run every six days at a random minute and hour ONLY ONCE on that day. Would this work? */30 */3 * * */6 command ... (3 Replies)
Discussion started by: Ashberry
3 Replies

3. Shell Programming and Scripting

How to compare particular string, if it is equal put into a new file

Hi, I have a file (sample.txt) this file contains below text. ./au ./11.5.0 ./11.5.0/admin ./11.5.0/admin/driver ./po ./11.5.0 ./11.5.0/admin ./11.5.0/admin/driver ./xxsbx/11.5.0/java/src ./xxsbx/11.5.0/lib ./xxsel ./xxsel/11.5.0 ./xxsel/11.5.0/admin ./zfa ./zfa/11.5.0... (2 Replies)
Discussion started by: gagan4599
2 Replies

4. Shell Programming and Scripting

Extract columns from a file if the name dont exist put blank

Hi, I am very new to Unix script. Suppose i have a file with column header: NAME1 NAME2 Address Tel And I always need to make a file with column header: ID NAME1 NAME2 EMail Address Tel For the columns that do not exist in the file, I would still like to make a column with blank. ... (11 Replies)
Discussion started by: nightrider
11 Replies

5. Shell Programming and Scripting

put string end of the line

I've a problem to put .h end of the line..below my input file fg_a bb fg_b bb fg_c bb fg_d aa fg_f ee and i want the output file as below fg_a.h bb fg_b.h bb fg_c.h bb fg_d.h (6 Replies)
Discussion started by: zulabc
6 Replies

6. Shell Programming and Scripting

How to use sed to put string end of line?

I have several file as below, and i want to put .txt to specific text contain ^main=EXE^cmd=run script /usr/prog/bd_, file1 7.9102 12.1528 16.3672 7.4002 ^main=EXE^cmd=run script /usr/prog/bd_123^" line 16.3672 7.3134 17.8711 6.0981 file 2 7.9102 12.1528 16.3672 7.4002 ... (8 Replies)
Discussion started by: zulabc
8 Replies

7. Red Hat

Dummy Question, put a script on startup fails

Hi all, im pretty new to unit/redhat 6.2 I am trying to load a script upon startup of my redhat 6.2 (instance in ec2 AWS if someone cares) I want everytime when instance starts (after stop/reboot) a script i build to launch. when i run the script ./scriptname the script runs and everything is... (4 Replies)
Discussion started by: hookedatwalla
4 Replies

8. Programming

How to put dot(.) in a string in C?

Hi all, Can anybody please tell me how can I put dot(.) in a string using C programming. for example -- I am having string "10111988" and I want to convert it as "10.11.1988" I will appriciate and thanks in advance.. (4 Replies)
Discussion started by: smartgupta
4 Replies

9. Shell Programming and Scripting

Put a string to the beginning of a file without a linefeed

Hello, I need to put the following string to the beginning of a file - but it should not create a newline at the end of the string. So, the file I have is a compressed one - with gzip. And I would like to add an ASCII-String to the beginning of the file. The string has a length of 69... (5 Replies)
Discussion started by: API
5 Replies

10. Shell Programming and Scripting

Printf or any other method to put long string of spec characters - passing passwords

Hello, I am looking for a method to use in my bash script which allows me to use long strings with all special characters. I have found that printf method could be helpful for me but unfortunately, when I trying root@machine:~# tevar=`printf "%s%c"... (2 Replies)
Discussion started by: elxa1
2 Replies
All times are GMT -4. The time now is 04:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy