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
Discussions
Discussions
Forums
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
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
тАО02-20-2005 11:43 AM
тАО02-20-2005 11:43 AM
07:37:46 file1.txt 02/12/06
07:35:48 file 2.txt 02/12/06
07:36:55 file3.txt 02/12/06
If you notice the 2nd record has a space as part of the file name so awk is treating this as a field separator.. Is there a way to get awk to include the space so I get the entire file name extracted in the 2nd record?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2005 12:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2005 05:02 PM
тАО02-20-2005 05:02 PM
Re: awk
Since you text file has lines with common words "txt" and "file",
you can change your file to do a global replacement with a comma in front of file and after txt. To modify vi the file and do this
:1,$s/file/,file/g and then save the file
Then again :1,$s/txt/txt,/g and save the file.
Eg:-
Original file conntents
07:37:46 file1.txt 02/12/06
07:35:48 file 2.txt 02/12/06
07:36:55 file3.txt 02/12/06
The modified file contents
07:37:46 ,file1.txt, 02/12/06
07:35:48 ,file 2.txt, 02/12/06
07:36:55 ,file3.txt, 02/12/06
Now you can use awk to list he files names as follows.
awk -F, '{ print $2 }' filename
This will output the file names.
file1.txt
file 2.txt
file3.txt
Indira A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2005 05:12 PM
тАО02-20-2005 05:12 PM
Re: awk
we can do as,
# cat > testfile
07:37:46 file1.txt 02/12/06
07:35:48 file 2.txt 02/12/06
07:36:55 file3.txt 02/12/06
# awk '{ if (NF==4) { print $2$3 } else { print $2 } }' testfile
file1.txt
file2.txt
file3.txt
it will check that if a input line is containing 4 fields then it will add 2nd and 3rd. Else it will display only 2nd.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2005 05:40 PM
тАО02-20-2005 05:40 PM
Re: awk
sed 's;\(..:..:.. \)\(.*\)\(../../..\)$;\2;' yourfile
regards,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2005 07:01 PM
тАО02-20-2005 07:01 PM
Re: awk
I prefer to think a little before answer. I assume the following:
a) first field is ALWAYS a timestamp in the format HH:MM:SS
b) last field is ALWAYS a date in the format xx/yy/zz...
then first and last fields won't contain blanks.
c) everything between first and last fields is a file name.
My first proposal would be:
awk '{ NAME=""; for(i=2; i
It works fine if blank chars in file name are single (i.e. not more than one blank) and file name doesn't begin nor end in blank chars -- I assume that JUST a blank char is used as separator in the original line.
A better proposal will remove the first field (plus a blank char after it) and last field (plus a blank char befor it) from the original line... leaving alone the file name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2005 07:19 PM
тАО02-20-2005 07:19 PM
Re: awk
cat /tmp/testfile | while read a
do
templength=`echo $a | wc -m`
let length=templength-10
echo $a | cut -c10-$length
done
This assumes that you always have a time record at the start and date record at the end (both are always the same length and the script strips the front and end 10 characters).
All the best - Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2005 07:23 PM
тАО02-20-2005 07:23 PM
Re: awk
awk '
{
LINE=$0 # needed to preserve original line and fields.
sub("^[[:blank:]]*" $1 ".", "", LINE) # remove first field plus a separator char
sub("." $NF "[[:blank:]]*$", "", LINE) # remove a separator char plus last field
print LINE
}'
one doubt: I'm not sure if char class [[:blank:]] is more suitable than [[:space:]].
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2005 10:46 PM
тАО02-20-2005 10:46 PM
Re: awk
read a line from your file into a variable (in this case, ${line}) then let ksh do it:
temp=${line#* }
fname=${temp% *}
This works whether or not there is a space in the filename on $line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2005 11:09 PM
тАО02-20-2005 11:09 PM
Re: awk
while read line
do
temp=${line#* }
fname=${temp% *}
echo $fname
done < tt
10 points to Gordon.