Open Tech archive
Sharing what I know!!!
About Me
Prakash
Working as Technical Lead in CollabNET software private limited.
View my complete profile
Showing posts with label
schellscript
.
Show all posts
Showing posts with label
schellscript
.
Show all posts
Thursday, 18 September 2008
AWK IF ELSE block
nawk -F"," ' BEGIN{OFS=","} {if (NR==1) {
print "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx"
} else {
print $1,$2,$3,$4,"S",1
print $1,$2,$3,$5,"S",2
print $1,$2,$3,$6,"D",1
print $1,$2,$3,$7,"D",2
}}' in.txt
Wednesday, 10 September 2008
Script to copy contents of file between two specific line patterns
Here is the script code to copy contents of files between two line patterns.
For example:
To copy the contents of file starting between the particular date and end date.
if [ $# -ne 3 ]; then
echo 1>&2 Usage: $0 file_to_parsed starting_pattern ending_pattern
exit 127
fi
startline=`grep -ni -m1 $2 $1 | awk -F ":" '{print $1}'`
endline=`grep -ni $3 $1 | tail -n1 | awk -F ":" '{print $1}'`
totallineno=`expr $endline - $startline + 1`
echo "Extracting contents between" $2 " and " $3
echo "No of lines found: " $totallineno
echo "Copying contents to temp file: " temp_file
echo "`head -n$endline $1 | tail -n $totallineno`" > temp_file
echo "Done copying."
Older Posts
Home
Subscribe to:
Posts (Atom)