cleanup $PATH with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cleanup $PATH with awk
# 15  
Old 06-17-2009
@Franklin52: With the export it is clear for me. It's only a question of getting the $PATH varaible cleaned up. I would do the export afterwards.
But your code
Quote:
Code:
PATH=`echo "$PATH" | awk -F":" '{for (i=1;i<=NF;i++)if(!x[$i]++)print $i}'`

doesn't work for me, besause I have spaces instead of colons between my directories after execution

@
ahmad.diab:
Quote:
Just add the below (in bold):-
Quote:

Code:
PATH=`printf "$PATH" | /usr/xpg4/bin/awk -v RS=':' -v ORS=":" '!a[$0]++'` | nawk 'NR==1'
BR
Didn't work for me, even, when I put the nawk expressions in the ` `
# 16  
Old 06-17-2009
Sorry I didn't test the command, try this:

Code:
 export PATH=`printf "$PATH" | /usr/xpg4/bin/awk -F":" '{for (i=1;i<=NF;i++)if(!x[$i]++)printf("%s%s", $i,i==NF?"":":")}'

# 17  
Old 06-17-2009
Quote:
Originally Posted by doc_symbiosis
@Franklin52: With the export it is clear for me. It's only a question of getting the $PATH varaible cleaned up. I would do the export afterwards.
But your code
doesn't work for me, besause I have spaces instead of colons between my directories after execution

@
ahmad.diab:
Didn't work for me, even, when I put the nawk expressions in the ` `
Code:
PATH=`printf "$PATH\n" | /usr/xpg4/bin/awk -v RS=':' -v ORS=":" '!a[$0]++'
| nawk 'NR==1'`

# 18  
Old 06-17-2009
YEAH, that's it. Both solutions work like charm.

@Franklin52: except of the missing ` at the end of your line

Thank you both very much.

One last question: Where can I set the thread to solved? Didn't finf anything
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse Directory path - awk

Hi All, Need some help in parsing a directory listing .. output into 2 files Input file level1,/level2/level3/level4/ora001,10,IBB23 level1,/level2/level3/level4/ora001/blu1,,IBB23 level1,/level2/level3/level4/ora001/clu1,,IBB23 level1,/level2/level3/level4/ora002,,IBB24... (10 Replies)
Discussion started by: greycells
10 Replies

2. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

3. Shell Programming and Scripting

Return path of specific tag using awk

The below awk is used with the attached index.html and matches the specific user id in the sub portion with path of /rundb/api/v1/plugin/49/. The command does run but the output is blank. Something changed in the file structure as it used to work. So using the first line in the output: ... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

Variable of Path directory is not parsing in awk

Hi All, i had to split one files into 10 equally. For that i have coded below awk. OUTPUT_FILE=/home/sit/path/Files/file_EXPORT.lst DIR_NM=`dirname ${OUTPUT_FILE}` awk -v CURR_DATE="$(date +'%d-%m-%Y-%H-%M')" -v pth=$DIR_NM '{print >> pth/"tgt_file_name"CURR_DATE"_"NR%10 }' ${OUTPUT_FILE} ... (7 Replies)
Discussion started by: looney
7 Replies

5. AIX

Simple AWK cleanup/questions AIX

I have an unfortunate need to redo a bunch of disk settings on a VIOS on AIX, so I was putting together a quick script to scrub everything it has, make the changes, and then put the mappings back. It works, I just am trying to get my awk a bit more up-to-snuff and wanted to know the proper way to... (2 Replies)
Discussion started by: Vryali
2 Replies

6. Shell Programming and Scripting

sed/awk for extracting directory from file path

Hi, I have following path: set file_path = D:/forums/prac/somedir/new1/file1.txt or set file_path = E:/new/forums1/prac/somedir/new2/file2.txt I need to grep "somedir" from file path. In this case preceding directory "prac" remains same for both the paths, but directories preceding... (7 Replies)
Discussion started by: sarbjit
7 Replies

7. Shell Programming and Scripting

Copy respective path next to last column with awk

Hi to all, I have the short print out sample of the DOS command "dir S/" as showed below. Directory of C:\Program Files\Winamp\Skins\Bento\window 02/12/2010 11:35 p.m. <DIR> . 02/12/2010 11:35 p.m. <DIR> .. 11/12/2009 10:31 a.m. 13,556... (3 Replies)
Discussion started by: cgkmal
3 Replies

8. Shell Programming and Scripting

Trouble with a file path as awk output in for loop

When I run the following command in the shell it works fine. It prints a city name and then a path for a file. ~$ for i in `awk -F':' '{print $0}' /home/knoppix/Desktop/data/subs | grep -m 1 $ city | sed "s/:/ /"` >do >echo $i >done Now, when I place it in this shell script (sh) it prints... (6 Replies)
Discussion started by: afroCluster
6 Replies

9. Shell Programming and Scripting

awk/sed/ksh script to cleanup /etc/group file

Many of my servers' /etc/group file have many userid's that does not exist in /etc/passwd file and they need to be deleted. This happened due to manual manipulation of /etc/passwd files. I need to do this for 40 servers. Can anyone help me in achieving this? Even reducing a step or two will be... (6 Replies)
Discussion started by: pdtak
6 Replies

10. Shell Programming and Scripting

Help with cleanup

I am trying to add a unique string to a variable to prevent some name space collisions. DATAFILE=/u001/app/unica/affinium644/campaign/partitions/limited/tmp/ebf9aaah.t~# DATETIME=`date +%Y%m%d_%H%M%S` echo $DATAFILE > tmpnme.txt sed 's_/_ _g' tmpnme.txt > tmpnme2.txt DATA=$(cat tmpnme2.txt)... (2 Replies)
Discussion started by: whdr02
2 Replies
Login or Register to Ask a Question