- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: file content replacement
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
тАО11-14-2005 06:38 PM
тАО11-14-2005 06:38 PM
I would like to ask how can i check if the ENDTIME field inside the file (please see attached file) has the correct format already and not "" - data? Subsequenty, If the data format is not correct the particular line content needed to be replaced.
I have attached a sample file. From the filename (DEV_1560_DC_1107_210610_S2.TDF), i need to extract the field 4th (1107) and 5th (210610) in the filename and place it in the ENDTIME line as
ENDTIME,20051107-210610
The 2005 is a prefix to the 4th field in the filename.
Maximum points for all correct answers.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-14-2005 06:54 PM
тАО11-14-2005 06:54 PM
Re: file content replacement
#awk 'BEGIN{split(ARGV[1],a,"_");}{if ( $0 ~ /ENDTIME/ ) {print "ENDTIME,2005"a[4]"-"a[5]; } else { print;}}' DEV_1560_DC_1107_210610_S2.TDF > test.TDF
# mv test.TDF DEV_1560_DC_1107_210610_S2.TDF
hth.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-14-2005 07:12 PM
тАО11-14-2005 07:12 PM
Re: file content replacement
With scripting:
#!/bin/ksh
# test.ksh
FILE=DEV_1560_DC_1107_210610_S2.TDF
PATTERN=$(echo "`date +'%Y'``echo $FILE | awk -F_ '{ print $4"-"$5 }'`")
sed -e "s/^ENDTIME,.*/ENDTIME,$PATTERN/g" $FILE > test.TDF
mv test.TDF > $FILE
# exit
exit 0
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-14-2005 07:23 PM
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-14-2005 07:55 PM
тАО11-14-2005 07:55 PM
Re: file content replacement
if I get it correct - there is a bit of testing to be done.
Attached, please find an approach using standard commands; the script should be able to handle all files listed in the directory which you have to specify (FULL_PATH_TO_FILES).
However, I would recommend that you, if you at all dare to uncomment the mv command line(!), enter a different destination path, in order not to overwrite your original files.
regards,
John K.