Execution problem ---to remove the lines which starts with one type of character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution problem ---to remove the lines which starts with one type of character
# 1  
Old 06-07-2012
Execution problem ---to remove the lines which starts with one type of character

Hi, I have one file, I need to check if file exist or not and then remove the lines which starts with ?
My file1.out data is some thing
Code:
abcabcppp
xyzxyzpqr
?????????
?????????

Output should be in test.out
Code:
abcabcppp
xyzxyzpqr

I am getting the output as below but the File does not exist in the directory..
I can see FN: is displayed in quotes "File1.out", Can some one please tell me what is wrong in this

I have written the following Code

Code:
#!/bin/ksh
set -A args $*
echo "Arguments "

outfile_string=${args[8]}
outfile_string=`echo ${outfile_string} | tr -d '"'` 
echo 'OUTFILE_STRING : '$outfile_string

FN=$USR/tmp/${args[8]}
echo "FN :" $FN
nfile_name=${args[9]}
nfile_name=`echo ${nfile_name} | tr -d '"'` 
echo 'Final File Name : '$nfile_name
 
#******** Check 
if test -s ${FN}
then
echo "File exist "
#ln_number=`grep -c '?' ${outfile_string}`
else 
echo "File does not exist "
fi

==========================================
Output for the above code
Code:
Arguments 
OUTFILE_STRING : File1.out
FN : /usr/tmp/"File1.out"
Final File Name : test.out
File does not exist

=============================================


If i declare this way
Code:
FN=$USR/tmp/${args[8]}

out put is
Code:
FN : /usr/tmp/"File1.out"

If i declare this way I am getting File Exist,
Code:
FN="$USR/tmp/File1.out"

Code:
FN : /usr/tmp/File1.out

but after this i need to search for the lines which start with ? and remove them and write to new file
Can some one please tell me how to do this.

Last edited by Scrutinizer; 06-07-2012 at 10:24 AM.. Reason: code tags
# 2  
Old 06-07-2012
Bug try this

Code:
grep -v "^?" file

# 3  
Old 06-07-2012
I can't reproduce your problem with the quotes.

What command line was used to invoke the script?
What Operating System and version is this?
# 4  
Old 06-07-2012
I am running from oracle applications

My version is
$ cat /proc/version
Linux version 2.6.32-100.26.2.el5 (mockbuild@ca-build10.us.oracle.com)
(gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Tue Jan 18 20:11:49 EST 2011
# 5  
Old 06-07-2012
Mabe try an echo "$*" at the top of the script so we can see what parameters were used to call the script. I'm wondering of your database is using a different character set from your Shell, or perhaps your tr command doesn't work?
Note that test -s checks that the file exists AND is not empty. You would need test -f to just check whether the file exists.

In the end it is probably going to be easier to fix the program which writes the data file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove newline character from column spread over multiple lines in a file

Hi, I came across one issue recently where output from one of the columns of the table from where i am creating input file has newline characters hence, record in the file is spread over multiple lines. Fields in the file are separated by pipe (|) delimiter. As header will never have newline... (4 Replies)
Discussion started by: Prathmesh
4 Replies

2. UNIX for Beginners Questions & Answers

Remove lines ending with a certain character

I have a file of a content like this: abc_bla -def 800 abc_bla -def 802 abc_bla -def 804 abc_bla -def 806 abc_bla -def 808 abc_bla -def 810 abc_bla -def 812 abc_bla -def 814 ... abc_bla -def 898 abc_bla -def 900 abc_bla -def 902 abc_bla -def 904 ... abc_bla -def 990 abc_bla -def... (7 Replies)
Discussion started by: maya3
7 Replies

3. UNIX for Beginners Questions & Answers

File name starts with esc character.

How can I refer to a file named esc[G ? I need to delete it or move it. TIA (5 Replies)
Discussion started by: wbport
5 Replies

4. Shell Programming and Scripting

File lines starts with # not processed or exclude that lines from processing

I have a file like below #Fields section bald 1234 2345 456 222 abcs dddd dddd ssss mmmm mmm mmm i need do not process a files stating with # I was written code below while read -r line do if then echo ${line} >> elif then ... (3 Replies)
Discussion started by: Chenchireddy
3 Replies

5. Shell Programming and Scripting

File lines starts with # not processed or exclude that lines

I have requirement in my every files starting lines have # needs to be not processing or exclude the that lines. I have written a code like below, but now working as expected getting ERROR" line 60: 1 #!/bin/sh 2 echo ======= LogManageri start ========== 3 4 #This directory is... (1 Reply)
Discussion started by: Chenchireddy
1 Replies

6. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

7. UNIX for Dummies Questions & Answers

Remove 1st character in periodic lines

Hi, I have a file that looks like this, the unity of information is composed of four lines, and these extends for millions. My objective is to remove the highligthed "T". How to attack this? This character is always constant in type "T" and position "1st" but the rest of the line is... (7 Replies)
Discussion started by: sargotrons
7 Replies

8. UNIX for Dummies Questions & Answers

Display lines not starts with #

hiiiii $ grep ^"#" $file Will give the lines , which starts with # .And I wanna get the lines which are not starting with #. How to implement that. Thanking you Krish:b: (10 Replies)
Discussion started by: krishnampkkm
10 Replies

9. UNIX for Advanced & Expert Users

remove lines from file where > 13 occurrences of character

I have a '~' delimited file of 6 - 7 million rows. Each row should contain 13 columns delimited by 12 ~'s. Where there are 13 tildes, the row needs to be removed. Each row contains alphanumeric data and occasionally a ~ ends up in a descriptive field and therefore acts as a delimiter, resulting... (7 Replies)
Discussion started by: kpd
7 Replies

10. Shell Programming and Scripting

How do I remove lines that have more than one of a certain character in them?

I have a file with a few thousand lines and I'd like to remove all the lines that have more than 1 asterik (the * character) in it. So if it has 2 or more in a single line, I'd like the line removed (double d command in vi) (12 Replies)
Discussion started by: guitarscn
12 Replies
Login or Register to Ask a Question