- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: file content
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
10-23-2005 06:51 PM
10-23-2005 06:51 PM
file content
I have a file that contains the following line
...
...
ENDTIME,"" -
...
...
ENDTIME record format is not correct so i need to manipulate it.
I have created a script like this:
endtime=$(awk -F "," '/ENDTIME/ {print $2}' $FILE)
if [ $endtime = "/"" - /" ]
then
lot=$(basename $FILE)
lot=`echo $edlot|sed 's/\.tdf//'`
lotdate=$(echo $edlot|awk -F _ '{print $4}')
lottime=$(echo $edlot|awk -F _ '{print $5}')
echo $year$lotdate"-"$lottime
exit
fi
but nothing seems to happen.
I need to replace the endtime record if it has erraneous content.
Maximum points to all correct answers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2005 07:01 PM
10-23-2005 07:01 PM
Re: file content
...
...
ENDTIME,"" -
...
...
how do you want to generate from this? plz specify the output you are executing. And more, your script is having more problem (without exact shell format). Revert back with details to get HUGE response(s).
-Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2005 07:23 PM
10-23-2005 07:23 PM
Re: file content
Basically i have a filename named BGC5043_6678_DC2_1005_154042_S3.TDF.
The content of the file has a line ENDTIME,"" - , in it.
All i want is to replace "" - with the correct time format (yearmmdd-hhmmss). which is actually within the filename (4th & 5th field).
The shell format is POSIX.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2005 08:07 PM
10-23-2005 08:07 PM
Re: file content
#!/bin/ksh
# Use format as: script.ksh
# EXample:
# ./script.ksh BGC5043_6678_DC2_1005_154042_S3.TDF
FILE=${1}
YD=$(echo "${FILE}" | awk -F"_" '{ print $4 }')
THS=$(echo "${FILE}" | awk -F"_" '{ print $5 }')
perl -pi -e "s%"" -%$YD-$THS%g" ${FILE}
# END #
exit 0
It will work.
# perl -pi -e "s%"" -%$YD-$THS%g" ${FILE}
# cat *.TDF
...
...
ENDTIME,""1005-154042
...
...
#
-Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2005 08:24 PM
10-23-2005 08:24 PM
Re: file content
In your output file, ENDTIME,""1005-154042
the "" should be 2005.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2005 08:26 PM
10-23-2005 08:26 PM
Re: file content
# perl -pi -e 'BEGIN{($YD,$HMS)=(split /_/,$ARGV[0])[3,4];}{s%ENDTIME,"".*$%ENDTIME,$YD-$HMS%g;}'
# perl -pi -e 'BEGIN{($YD,$HMS)=(split /_/,$ARGV[0])[3,4];}{s%ENDTIME,"".*$%ENDTIME,$YD-$HMS%g;}' BGC5043_6678_DC2_1005_154042_S3.TDF
# cat BGC5043_6678_DC2_1005_154042_S3.TDF
...
...
ENDTIME,1005-154042
...
...
-Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2005 08:30 PM
10-23-2005 08:30 PM
Re: file content
#!/bin/ksh
# Use format as: script.ksh
# EXample:
# ./script.ksh BGC5043_6678_DC2_1005_154042_S3.TDF
FILE=${1}
Y=$(date +'%Y')
MD=$(echo "${FILE}" | awk -F"_" '{ print $4 }')
THS=$(echo "${FILE}" | awk -F"_" '{ print $5 }')
perl -pi -e "s%ENDTIME,"".*$%ENDTIME,$Y$YD-$THS%g" ${FILE}
# END #
exit 0
# ksh script.ksh
will do it.
-Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2005 08:41 PM
10-23-2005 08:41 PM
Re: file content
# perl -pi -e 'BEGIN{$Y=`date +'%Y'`;chomp($Y);($YD,$HMS)=(split /_/,$ARGV[0])[3,4];}{s%ENDTIME,"".*$%ENDTIME,$Y$YD-$HMS%g;}'
It will update into the file itself.
hth.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2005 08:58 PM
10-23-2005 08:58 PM
Re: file content
One more thing before i made my final points.
Is it possible to test if the ENDTIME field contains the date and time format like yyyymmdd-hhmmss?
I am asking this this because some files have the correct format and others do not have.
My plan is to correct the wrong format then process it. If it is already correct then it will process them as is.
I need to process 10,000 files in my hp-ux system. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2005 11:33 PM
10-23-2005 11:33 PM
Re: file content
Will change when ENDTIME is having format as,
ENDTIME,""
To make check if ENDTIME,YYYYMMDD-HHMMSS
# perl -pi -e 'BEGIN{$Y=`date +'%Y'`;chomp($Y);($YD,$HMS)=(split /_/,$ARGV[0])[3,4];}{s%ENDTIME,"".*$%ENDTIME,$Y$YD-$HMS%g if /ENDTIME,\d{6}-\d{6}/;}'
-Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2005 11:48 PM
10-23-2005 11:48 PM
Re: file content
> Is it possible to test if the ENDTIME
> field contains the date and time format
> like yyyymmdd-hhmmss?
either
# perl -e'BEGIN{@d=localtime;$ENDTIME=sprintf"%4d%02d%02d-%02d%02d%02d",$d[5]+1900,$d[4]+1,@d[3,2,1,0]} ...'
or (but slower) using POSIX
# perl -MPOSIX=strftime -e'BEGIN{ENDTIME=strftime"%Y%m%d-%H%M%S",localtime} ...'
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2005 07:47 PM
10-25-2005 07:47 PM
Re: file content
Can you explain to me the line below. I think this would check if ENDTIME,YYYYMMDD-HHMMSS
,if not what would happen?
# perl -pi -e 'BEGIN{$Y=`date +'%Y'`;chomp($Y);($YD,$HMS)=(split /_/,$ARGV[0])[3,4];}{s%ENDTIME,"".*$%E
NDTIME,$Y$YD-$HMS%g if /ENDTIME,\d{6}-\d{6}/;}'