![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to search for files based on the time stamp | sunny_03 | UNIX for Dummies Questions & Answers | 1 | 02-12-2008 09:45 AM |
| Append Header and Trailer | balzzz | UNIX for Dummies Questions & Answers | 2 | 01-06-2008 08:19 AM |
| Need to delete the files based on the time stamp of the file | samudha | UNIX for Dummies Questions & Answers | 2 | 06-20-2007 08:02 AM |
| Count No of Records in File without counting Header and Trailer Records | guiguy | Shell Programming and Scripting | 2 | 06-07-2007 01:15 PM |
| Remove header(first line) and trailer(last line) in ANY given file | madhunk | Shell Programming and Scripting | 2 | 03-13-2006 03:36 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Copy all the files with time stamp and remove header,trailer from file
All,
I am new to unix and i have the following requirement. I have file(s) landing into input directory with timestamp, first i want to copy all these files into seperate directory then i want to rename these files without timestamp and also remove header,trailer from that file.. Could anybody please throw some light on this how to write a script for above requirement .. Thanks in advance.. |
|
||||
|
Thanks for quick reply Shell_Life.
Quote:
Input file(s) located under directory /input and file names are: 1) input1_20070723_171556.txt 2) input2_20070723_171556.txt 3) input3_20070723-171556.txt input1_20070723_171556.txt sample data: HEADERRECORD 20070723 DESC aaa 111 222 333 bbb bbb 222 111 444 ccc ccc 333 444 111 ddd TRAILERRECORD 3 I want the do the following process in one script.. a) First thing is i want to copy all the files into /ouput directory b) rename the files under /out directory to 1) rename input1_20070723_171557.txt file to input1.txt and also remove HEADERRECORD 20070723 DESC(header record i.e always first line) and TRAILERRECORD 3(Detail record i.e always last line in file) from input1.txt input1.txt file data should be: aaa 111 222 333 bbb bbb 222 111 444 ccc ccc 333 444 111 ddd 2) rename input2_20070723_171557.txt to input2.txt and also remove first and last lines from input2.txt 3) rename input3_20070723_171556.txt to input3.txt and also remove first and last lines from input3.txt I hope this is much better compare to my previous post. I would appreciate if you guide me on this.. Thanks in advance.. |
|
||||
|
Script
I think this script should help you Code:
#!/bin/ksh
Input_Dir="$HOME/input"
Output_Dir="$HOME/out"
rm -f $Output_Dir/*
for file in `ls $Input_Dir` # If the input directory contains only files
# for file in `ls -l $Input_Dir | grep '^-' | awk '{print $9}'` #Only files in Dir
do
new_file=${file%%_*}
wc -l $Input_Dir/$file | awk '{ print $1}' | read line_count
sed "1d;$line_count""d" $Input_Dir/$file > $Output_Dir/$new_file.txt
touch -r $Input_Dir/$file $Output_Dir/$new_file.txt
done
exit
|
|
||||
|
Quote:
Input files not always starts with input*.txt,input files could start with any name.I want to process all the files under input directory and filename last 20 characters are always timestamp.txt..Could you please modify this script to process all the files instead of input*.txt files.Would it possible if we pass input and output directories as parameters to this script. Thanks in advance.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|