- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script help
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
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
12-15-2003 04:35 PM
12-15-2003 04:35 PM
The input file looks like this.
abc_abcsgsap_PRD Aborted trans 12/16/03 05:00:00 1071522000 12/16/03 09:38:30 1071538710 0:004:38 0.00 0 1 4 0 0 1 0 1 0 0% root.sys@mwscm.esc 2003/12/16-12
abc_abcsapdev_DEV Completed trans 12/16/03 05:00:06 1071522006 12/16/03 05:02:02 1071522122 0:00 0:01 0.18 1 0 2 0 0 0 5 5 5 100% root.sys@mwscm.esc 2003/12/16-13
abc_abcgqa_QAS Completed trans 12/16/03 05:00:11 1071522011 12/16/03 05:03:19 1071522199 0:000:03 0.32 1 0 3 0 0 0 4 4 4 100% root.sys@mwscm.esc 2003/12/16-14
abc_abcsgsap In Progress full 12/16/03 13:19:29 1071551969 - 0 0:00 0:14 6.14 1 04 1 4 0 3 8 12822 38% SPOP\E-SERVICES@spop.esc 2003/12/16-27
After processing the output should be like this.
field1;field2;field3
I have attached part of my script. Currently the problem is my script cannot differentiate between tab and space if the input file contain a field like "In Progress", it will actually create as field1;In;Progress; intead of field1;In Progress.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2003 06:03 PM
12-15-2003 06:03 PM
Solutionecho "${LINE}" | sed -e 's/ /;/g' >>${DESTDIR}/${FILENAME}
Be sure to use a TAB between the first two slashes.
When you want only specific fields, use awk with a TAB as field-separator:
echo "${LINE}" | awk -F" " '{ print ... }' >>${DESTDIR}/${FILENAME}
Again, be sure to use a TAB as the argument of the -F option of awk.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2003 06:22 PM
12-15-2003 06:22 PM
Re: script help
cat myfile | tr "\t" ":"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2003 06:26 PM
12-15-2003 06:26 PM
Re: script help
The replacement doesn't need the echo. It can be done this way:
sed 's|^I|;|g'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2003 07:29 PM
12-15-2003 07:29 PM
Re: script help
Therefore your simplest way forward is an amalgam of the above suggestions, just change
awk '{printf $1 ...
to
awk -F"\t" '{printf $1 ...
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2003 07:59 PM
12-15-2003 07:59 PM
Re: script help
Just one more question, is there any easyway in sed I can remove some fields using semicolon as delimitier.
For example I have
field1;field2;field3;field4
I want to remove all field2 and field4 from the file.
Currently I use a loop to read through line by line and do a print $1 $3 to just print out field1;field3.
I think this is very troublesome
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2003 08:05 PM
12-15-2003 08:05 PM
Re: script help
awk -F";" '{printf ("%s;%s\n", $1, $3)}' infile > outfile
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2003 08:07 PM
12-15-2003 08:07 PM
Re: script help
awk -F";" '{print $1,$4}' datafile
Although this looks like the same thing, if your data is already in the file datafile or if you pipe the data into this awk thing then you will not need to do the loop yourself and it will be much faster.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2003 09:29 PM
12-15-2003 09:29 PM
Re: script help
cut -d\; -f1,3,5-
Using sed, it becomes trickier...
It depends on how many fields you have in the input. If it is always more then 4, sed would look like this:
sed 's|^\([^;]*;\)[^;]*;\([^;]*;\)[^;]*;\(.*\)$|\1\2\3|'
I would go for cut or awk, not for sed in this case...