- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help with awk script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 05:25 AM
09-05-2002 05:25 AM
What I am trying to do is use this file to 1st - delete the 1st file in the line, so we can remove the copy (which should be a link), 2nd recreate the symbolic link listed in this file (as the second file listed on the line is the actual code, the link needs to be recreated from that point to the 1st file listed on the line). Since I know there are some scripting God's out there, as I work on it, any input would be quite appreciated!!! I was going to attempt to use awk, using the '->' as a field separator. Then put the 2nd filename 1st for the ln -s command to the second filename to relink.
Here is the format of the linklog file that lists 551 lines of all links within our customer directories, I am also attaching the entire file:
lrwxrwxrwx 1 382 15 50 Jan 18 2002 /opt/cs3000/pca/funded
/1004131/script/cnutr105.sh,v -> /opt/cs3000/pca/funded/W43392/script/cnutr105.sh,v
ugh... If I get a solution and you are going to LA, I'll definitely buy you a beer!!! :)
Thanks!
Lisa
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 05:44 AM
09-05-2002 05:44 AM
Re: Help with awk script
See if this fits your needs:
awk '{print "rm",$5;print "ln -s",$7,$5}' filein > fileout
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 05:44 AM
09-05-2002 05:44 AM
SolutionI have one way to do it. Using your file of links (named links.txt and removed blank lines at the beginning and the end), I ran this awk command to create a file that will remove the first file and create the symlinks:
awk '{printf("rm %s\nln -s %s %s\n", $9, $11, $9)}' links.txt >links.sh
This creates the links.sh file, which looks like this (first couple of lines):
head -4 links.sh
rm /opt/cs3000/pca/funded/1004131/cobol/PNBUT11F.CBL,v
ln -s /opt/cs3000/pca/funded/W43392/cobol/PNBUT11F.CBL,v /opt/cs3000/pca/funded/
1004131/cobol/PNBUT11F.CBL,v
rm /opt/cs3000/pca/funded/1004131/script/cnutr105.sh,v
ln -s /opt/cs3000/pca/funded/W43392/script/cnutr105.sh,v /opt/cs3000/pca/funded/
1004131/script/cnutr105.sh,v
Does that look like what you are looking for?
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 05:45 AM
09-05-2002 05:45 AM
Re: Help with awk script
here my quick and dirty awk:
awk '{
f1=$(NF-2)
f2=$NF
print "rm " f1
print "ln -s " f2 " " f1
}' ls_file >link_recreate.sh
then run sh link_recreate.sh
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 05:48 AM
09-05-2002 05:48 AM
Re: Help with awk script
But here is what I did.
(put your list in a file say an)
Seperate the link with command
awk -F " " '{print $9}' an
(this gives listing of links)
Seperate actual files(lat feild in a file an)
awk -F " " '{print $NF}' an
Now I have two lists first is link and second actual list.
Give details what exactly you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 05:49 AM
09-05-2002 05:49 AM
Re: Help with awk script
Oops, sorry, I can't count. That should be:
# awk '{print "rm",$5;print "ln -s",$9,$11}' filein > fileout
Regards!
...JRF..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 05:51 AM
09-05-2002 05:51 AM
Re: Help with awk script
awk '{print "rm",$5;print "ln -s",$11,$9}' filein > fileout
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 05:53 AM
09-05-2002 05:53 AM
Re: Help with awk script
I just thought of another way to tackle the problem. You could do another backup using find to just grab the symlinks and cpio to backup the symlinks, and then just overwrite the files on the new system.
find /opt/cs3000 -type l | cpio -ocm >/var/tmp/rcslinks.cpio
Copy the rcslinks.cpio to the new system and:
cpio -ivmcu
Or something like that. That should overwrite the files with the symlinks.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 06:01 AM
09-05-2002 06:01 AM
Re: Help with awk script
I don't think I can count using the numbers I should :-((
# awk '{print "rm",$9;print "ln -s",$11,$9}'
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 09:26 AM
09-05-2002 09:26 AM
Re: Help with awk script
Thanks again!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 09:38 AM
09-05-2002 09:38 AM
Re: Help with awk script
/NO_MORE_POINTS_PLEASE/
I never meant for my bungled typing to receive points -- only the last of my corrections!
The use of the last field (NF) in Andreas Voss' solution is the superior answer. By using relative field numbers, like:
# awk '{print "rm",$(NF-2)9;print "ln -s",$NF,$(NF-2)}' filein > fileout
...you can handle input created by 'ls -l' or 'ls -ls' where the addition of the '-s' option adds another field and shifts the field containing the filename downstream.
/NO_MORE_POINTS_PLEASE/
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2002 09:59 AM
09-05-2002 09:59 AM
Re: Help with awk script
Thanks again!