- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sed, ed, (hurts my head)
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
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
08-06-2002 09:25 AM
08-06-2002 09:25 AM
sed, ed, (hurts my head)
I have a large text file and was wondering what the easiest way would be to replace "whitespace" between fields (words) with "tabs". is this possible? Each field in the file starts at a specific character position, but was hoping there was an easy way of just replacing whitespace with a tab.
Ideas? Suggestions? Flames?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 09:31 AM
08-06-2002 09:31 AM
Re: sed, ed, (hurts my head)
cat
ET voila
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 09:37 AM
08-06-2002 09:37 AM
Re: sed, ed, (hurts my head)
Here's a couple of handy references to sed and awk commands, originally (to me, at least) courtesy of Princess Paula.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 09:38 AM
08-06-2002 09:38 AM
Re: sed, ed, (hurts my head)
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 10:04 AM
08-06-2002 10:04 AM
Re: sed, ed, (hurts my head)
how about "unexpand" ???
see "man unexpand"
good luck,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 10:19 AM
08-06-2002 10:19 AM
Re: sed, ed, (hurts my head)
I'm trying to load a text file into MySQL, and it has to be tab delimited. And the original text file's field delimination is by ASCII Character Position.
Me thinks this is going to be complicated ;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 10:23 AM
08-06-2002 10:23 AM
Re: sed, ed, (hurts my head)
Give us one line before and after the format. Then we may help you better.
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 10:34 AM
08-06-2002 10:34 AM
Re: sed, ed, (hurts my head)
cat file | sed -e "s/ /\t/g"
Note that \t should be replaced by the tab character.
The "g" does the global replace.
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 10:42 AM
08-06-2002 10:42 AM
Re: sed, ed, (hurts my head)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 10:42 AM
08-06-2002 10:42 AM
Re: sed, ed, (hurts my head)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 10:44 AM
08-06-2002 10:44 AM
Re: sed, ed, (hurts my head)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 11:17 AM
08-06-2002 11:17 AM
Re: sed, ed, (hurts my head)
while read LINE
do
firstfield=`echo $LINE | cut -c 2-10`
secondfield=`echo $LINE | cur -c 11-20`
printf( "%s\t%s\n", $firstfield, $secondfield)
done < inputfile
Make a "firstfield" definition for each field in the record.
Personally, I think this would probably be easier to write in C (certainly much faster to execute), but I'm guessing you don't know C.
Good luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 11:40 AM
08-06-2002 11:40 AM
Re: sed, ed, (hurts my head)
Here's my script:
=======================
while read LINE
do
time=`echo $LINE | cut -c 3-6`
duration=`echo $LINE | cut -c 8-11`
conncode=`echo $LINE | cut -c 12-13`
acccode=`echo $LINE | cut -c 15-17`
acccode2=`echo $LINE | cut -c 19-21`
dialed=`echo $INE | cut -c 23-37`
originate=`echo $LINE | cut -c 39-43`
printf( "%s\t%s\n", $time, $duration, $conncode, $acccode, $acccode2, $dialed, $originate)
done < inputfile
=========================
I ran piped the text file through this:
cat txtfile | converterprg
I get this error:
./converter: line 11: syntax error near unexpected token `"%s\t%s\n",'
./converter: line 11: `printf( "%s\t%s\n", $time, $duration, $conncode, $acccode, $acccode2, $dialed, $originate)'
I'm not sure what this means...
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2002 11:48 AM
08-06-2002 11:48 AM
Re: sed, ed, (hurts my head)
s/\(...\) *\(....\) *\(.....\)/\1\t\2\t\3\t/
This will take three fields of 3,4 and 5 characters respectively, delimited by any number of spaces (including none) and format the same three fields but seperated by a 'tab' character.
i.e. \(...\) takes the first 3 characters and \1 places these in the output.
Change the ... to denote the characters that you require (for many characters use the notation .{m} where m is the number of characters. For whitespace use ['space'tab']* instead of space* or spacespace* which must match at least one space
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2002 05:03 AM
08-07-2002 05:03 AM
Re: sed, ed, (hurts my head)
Anyway, with these variables you defined:
time=`echo $LINE | cut -c 3-6`
duration=`echo $LINE | cut -c 8-11`
conncode=`echo $LINE | cut -c 12-13`
acccode=`echo $LINE | cut -c 15-17`
acccode2=`echo $LINE | cut -c 19-21`
dialed=`echo $INE | cut -c 23-37`
originate=`echo $LINE | cut -c 39-43`
You should use this syntax (in ksh):
printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\n" "$time" "$duration" "$conncode" "$acccode" "$acccode2" "$dialed" "$originate"
Good luck!