Hi, I have a Text file. some records ends with 316byte length and some with 315. I want each to be end with 320 length. I just want to add space in end of each record.
IF a record ends with 315 then include 5spaces
IF a record ends with 316 then include 4spacesPlease help in this
thanks,
Umar
Thsi might give yuo a hint: #!/bin/bash # min file length ml=320 # set working directory wd="/tmp/ttt" # change to the working directory cd "$wd" # read filenames in working directory for file in $(ls) do # seperate file length from ls -l fl=$(ls -l $file | awk '{print $5}') # set x to current file length and check whether it's less than min file length for (( x = fl; x < ml; x++ )) do # echo whitespace to current file echo -n " " >> $file done doneClick Here on HowTo ask good Question to get best Help
Let us know, if the problem is solved !!!
Try this. Just change the file names to match the ones you have. #!/bin/ksh
OLDIFS=$IFS
IFS="
"exec 3< myfile
while read -u3 line
do
if [[ ${#line} -eq 315 ]]
then
line="$line "
else
line="$line "
fi
print ${line} >> myfile.new
donemv myfile myfile.orig
mv myfile.new myfileIFS=$OLDIFS
@paulsep, please don't impart the wrong things to newbies. Don't parse files using `ls`. use shell expansion for file in * do ... size=$(stat -c "%s" $file) ... done
to get the file size, use the stat command (or the find command).
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |