Working on column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Working on column
# 1  
Old 04-20-2011
Working on column

Hi everybody,

I am actually scripting some command on column coordinate files and i wish to replace such example:
Code:
004.2990333W 47.7960333N
004.2983667E 47.7960833S

Thus
Code:
-004.2990333 47.7960333N
004.2983667 -47.7960833S

(replacing west and south by "-" , and east and north by "no sign")

I am working on geographical system and rarely scripting in unix ..so if you might help ...

Thanks a lot.

Strongwave
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 04-20-2011 at 11:08 AM.. Reason: code tags, please!
# 2  
Old 04-20-2011
your sample output doesn't jive with your description, but...
Code:
nawk '{for(i=1;i<=NF;i++) {s=($i~/(W|S)$/)?1:0;printf("%s%s%c", s?"-":"", substr($i,1,length($i)-s), (i==NF)?ORS:OFS)}}' myFile

# 3  
Old 04-20-2011
this what you're after ?

Code:
#   nawk '{
for (i=1;i<=NF;i++){
if ($i~"W"){$i="-"substr($i,1,length($i)-1)}
if ($i~"S"){$i="-"$i}
if ($i~"E"){$i=substr($i,1,length($i)-1)}
}print}' infile
-004.2990333 47.7960333N
004.2983667 -47.7960833S

# 4  
Old 04-22-2011
Thanks guys

Sorry to for late feedback but thanks for the answer. It works perfectly!
Smilie

Have a nice day

Strongwave
# 5  
Old 04-22-2011
Damn S, it almost got me Smilie
Code:
sed -r 's/([0-9]*\.[0-9]*)((S)|W)/-\1\3/;s/E//' infile

Code:
~/unix.com$ cat infile 
004.2990333W 47.7960333N
004.2983667E 47.7960833S

~/unix.com$ sed -r 's/([0-9]*\.[0-9]*)((S)|W)/-\1\3/;s/E//' infile
-004.2990333 47.7960333N
004.2983667 -47.7960833S

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Disk Space Utilization in HTML format working in one environment and not working on the other

Hi Team, I have written the shell script which returns the result of the disk space filesystems which has crossed the threshold limit in HTML Format. Below mentioned is the script which worked perfectly on QA system. df -h | awk -v host=`hostname` ' BEGIN { print "<table border="4"... (13 Replies)
Discussion started by: Harihsun
13 Replies

2. Shell Programming and Scripting

Working web service call not working with curl

Hello, Newbie here, I have a perfectly well working web service call I can issue from chrome (PC Windows 10) and get the results I want (a dimmer being turned on in Fibaro Home Center 2 at level 40) I am not allowed to post urls but the below works with http and :// and... (3 Replies)
Discussion started by: abigbear
3 Replies

3. Shell Programming and Scripting

Automating pbrun /bin/su not working, whenever manually it is working using putty

I am trying to automate a script where I need to use pbrun /bin/su but for some reason it is not passing thru the pbrun as my code below. . ~/.bash_profile pbrun /bin/su - content c h 1 hpsvn up file path I am executing this from an external .sh file that is pointing to this scripts file... (14 Replies)
Discussion started by: jorgejac
14 Replies

4. Shell Programming and Scripting

Sort based on column 1, not working with awk

Hi Guru, I need some help regarding awking the output so it only show the first line (based on column) of each row. So If column has 1, three row, then it only show the first line of that row, based on similar character in column 1. So i am trying to achieve a sort, based on column one and... (3 Replies)
Discussion started by: Junes
3 Replies

5. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. Shell Programming and Scripting

Difference of the same column when two other column matches and one column differs less than 1 hour

This is my input file : # cat list 20130430121600, cucm, location,76,2 20130430121600,cucm1,location1,76,4 20130430122000,cucm,location,80,8 20130430122000,cucm1,location1,90,8 20130430140000,cucm1,location1,87,11 20130430140000, cucm,location,67,9 This is the required output ... (1 Reply)
Discussion started by: Lakshmikumari
1 Replies

7. Shell Programming and Scripting

need to get the total # of column for each line - NF not working

Hello, I just need to print the # of columns for each line of the input file. The input file uses the ascii 009 tab character. I specify this character as the FS (field separator) in the BEGIN section, and I know the FS character is correct because I can print it. When I try to print the #... (1 Reply)
Discussion started by: script_op2a
1 Replies

8. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

9. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

10. Shell Programming and Scripting

Question about working with data to create new column

Hello, I am having a problem with the script I am using to create a column from two columns I have in my file. I am needing to take column 5 and subtract it from column 2 to create column 6. I have included the script I am using and the rawdata I am using. Raw Data File:... (4 Replies)
Discussion started by: scottzx7rr
4 Replies
Login or Register to Ask a Question