![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cut a part of the file | kurosaki | Shell Programming and Scripting | 1 | 06-02-2008 06:14 AM |
| grep within certain part of file | Orbix | UNIX for Dummies Questions & Answers | 2 | 11-26-2007 03:45 AM |
| renaming part of a file | ajaya | Shell Programming and Scripting | 0 | 04-11-2006 07:00 PM |
| Add Date as part of file name | amsh76 | Shell Programming and Scripting | 3 | 09-05-2005 06:18 PM |
| Help with multiple file rename - change case of part of file name | steve7 | UNIX for Dummies Questions & Answers | 7 | 06-30-2005 10:41 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to delete part of a file?
Suppose i have a file which contains 10 lines....
i have to delete a line which starts with the word "BEGIN" and delete the consecutive lines till i find a start of line with the word "END" how to do this? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
sed -e "/^BEGIN/,/^END/d" in.txt > out.txt |
|
#3
|
|||
|
|||
|
Hi vino,
thatz gr8.this too works perfectly. Actually my problem is something different.i thought i can get clue from this answer. but.. i wanted to remove the code present in the macros of a C program like... #ifdef FLAG //some code //some code #endif if i give the argument as FLAG it shd remove all the code in that.. And the worst thing is this #ifdef can contain nested #ifdefs #else #elif all stuffs. how can i match the correct #endif?CAn u give me some clue? Regards, Kavitha. |
|
#4
|
||||
|
||||
|
Removing code between macros' is not an easy task.
Try man cpp. cpp as in C Preprocessor That should help you out. Code:
cpp -DFLAG -DANOTHER_FLAG -I/dir/with/header/files in.cpp out.cpp |
|
#5
|
|||
|
|||
|
Hi vino,
if u get time can u try this out? Execute it with ./scriptname <filename> <FLAG to be removed> as cmd line arguments FLAG=0 FOUND=0 C="#ifdef" T="${C} $2 exec 0<$1 set -f while read -r $line do if [ "$line" = "$T" ] ;then FLAG=1 FOUND=1 elif [ "$line" = "else" ] && [ $FOUND -eq 1 ] ;then FLAG=0 elif [ "$(echo $line | awk '{print $1}')" = "#endif" ] && [ $FOUND -eq 1 ] ;then FLAG=0 FOUND=0 elif [ $FLAG -ne 1 ] echo $line elif [ "$(echo $line |awk '{print $1}' )" = "#elif" ] ;then echo $line | sed 's/elif defined/if/' FLAG=0 FOUND=0 fi done >$1.tmp mv -f $1.tmp $1 REgards, Kavitha |
|
#6
|
||||
|
||||
|
What is the problem that you are facing ?
Did you get a chance to try out cpp ? |
|
#7
|
|||
|
|||
|
that doesn't work vino.
now tell me... i want to check if a word is present in a line,if present //do something... like the macro can be #if or "ifdef" or "if DEFINED(FLAG) if the line contains DEFINED(FLAG1) , then ///do something if [ grep <here i want to use the FLAG given in cmd line> ] since the C program contains ifdef statements like.. if defined(FLAG1) || defined(FLAG2) Regards, Kavitha |
|||
| Google The UNIX and Linux Forums |