- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- speces to be deleted from a file : scripted file
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
09-25-2005 03:41 AM
09-25-2005 03:41 AM
I have one script the output of the script looks like something below in a file now I want to upload this file in database as per my dba but he wants the tabs to be deleted between the column and this is a automated process please gude me what i should use after getting this file to remove the tabs and keep only a single space in columns:
Please make a note that I am new to the scripts
9 UW ETAAXE 20050706
10 UW ETAAXE 20050707
16 UW ETAAXE 20050711
1 UW ETAAXE 20050713
1 UW ETAAXE 20050715
1 UW ETAAXE 20050716
2 UW ETAAXE 20050722
1 UW ETAAXE 20050723
Thanks in advance
Regards,
Abhijit Panse
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 03:43 AM
09-25-2005 03:43 AM
Re: speces to be deleted from a file : scripted file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 03:53 AM
09-25-2005 03:53 AM
Re: speces to be deleted from a file : scripted file
You can do this:
# perl -ple 's/\s+/ /g' /tmp/datafile
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 06:20 AM
09-25-2005 06:20 AM
Re: speces to be deleted from a file : scripted file
cat your_file | tr -s [:space:] " " > new_file
The tr solution is useful because it collapses multiple occurances of Unix "white space" (tabs, spaces or combinations) into one space.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 09:34 AM
09-25-2005 09:34 AM
Re: speces to be deleted from a file : scripted file
Note too, that the perl solution collapses one or more "whitespace" (space or tab) into a single space.
The \s+ notation refers to one or more whitespace characters.
's/\s+/ /g' means substitute (the first "s") one or more occurances of whitespace with one space. The forward slash characters bound the target of the match and the substitution to make for the match. The 'g' says do this (g)lobally for every occurance you find on a line.
The -ple options essentially tell perl to (p)rint what is processed by (e)xecuting the commandline script following. The input file is named last on command line.
If you wanted to make sure that your filtered file not only eliminated tab characters; reduced spaces between columns to one space; and eliminated any leading or trailing whitespace, do:
# perl -ple 's/^\s+//g;s/\s+$//;s/\s+/ /g' filein > fileout
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 06:10 PM
09-25-2005 06:10 PM
Solution# awk '{ for (i=1;i<=NF;i++) { printf $i" " } printf "\n" }' /tmp/datafile
9 UW ETAAXE 20050706
10 UW ETAAXE 20050707
16 UW ETAAXE 20050711
1 UW ETAAXE 20050713
1 UW ETAAXE 20050715
1 UW ETAAXE 20050716
2 UW ETAAXE 20050722
1 UW ETAAXE 20050723
#
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 06:15 PM
09-25-2005 06:15 PM
Re: speces to be deleted from a file : scripted file
# perl -e ' while(<>){ split; $,=" "; print @_; printf "\n"; }' /tmp/datafile
9 UW ETAAXE 20050706
10 UW ETAAXE 20050707
16 UW ETAAXE 20050711
1 UW ETAAXE 20050713
1 UW ETAAXE 20050715
1 UW ETAAXE 20050716
2 UW ETAAXE 20050722
1 UW ETAAXE 20050723
# If you want to into the same file then,
# perl -i -e ' while(<>){ split; $,=" "; print @_; printf "\n"; }' /tmp/datafile
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 08:38 PM
09-25-2005 08:38 PM
Re: speces to be deleted from a file : scripted file
this format your file as requested:
tr -s [:space:] ' '
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 09:43 PM
09-25-2005 09:43 PM
Re: speces to be deleted from a file : scripted file
I think all suggestions by perl or tr are useful to obtain the goal....anyway I would use the classic vi commands too:
- open the file by vi and type the following:
:1,$s/
HTH.
Best regards,
Fabio
P.S.: Abhijit, please remember to let know us if the suggestions helped you...thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2005 09:48 PM
09-25-2005 09:48 PM
Re: speces to be deleted from a file : scripted file
:1,$s/
Therefore
Just to be more exact...
Best regards,
Fabio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2005 01:35 AM
09-26-2005 01:35 AM
Re: speces to be deleted from a file : scripted file
Thanks for your replies exact solution was from muthukumar as I have to do it from the script and AWK I can put it in my original script.
Anyways other solutions are good.
Thanks Regards,
Abhijit Panse