How to echo Brackets from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to echo Brackets from a file
# 1  
Old 05-27-2010
How to echo Brackets from a file

I'm a beginner of c shell scripting.
How I can echo a whole line from a file with bracket in it?
Ex. Inside the file.txt
abcd [5:0] efghi

This is what inside the c shell

Code:
set IN_FILE = file.txt
set GREP_KEY = 'abcd'
set IN_LINE = `grep ${GREP_KEY} ${IN_FILE}`
echo $IN_LINE

After excuting, the whole line containing 'abcd' won't display then I tried to remove the bracket from the file and it works.

Thank you.
Zeahr

Last edited by Scott; 05-27-2010 at 04:57 AM.. Reason: Please use code tags
# 2  
Old 05-27-2010
can you please tell us what ru trying to do. i mean in which way ur input data is and what desired output u want.

a small sample. ??
# 3  
Old 05-27-2010
Don't use C shell for scripting, if for anything. With a standard shell, that would be:
Code:
#!/bin/ksh
IN_FILE=file.txt
GREP_KEY=abcd
IN_LINE=$(grep $GREP_KEY $IN_FILE)
echo $IN_LINE

# 4  
Old 05-27-2010
Quote:
Originally Posted by zeahr
Code:
echo $IN_LINE

Maybe (- no C shell here ...):

Code:
echo "$IN_LINE"

# 5  
Old 05-27-2010
I'm trying to copy a line of a file with brackects in it and store the line temporarily in the variable and output it to a new file, and below that line I will write a new line before the second line of the old file is being written to the new file.

Old file:
Code:
0001 REG1 [7:0] Register 1
0002 REG2 [7:0] Register 2
0003 REG3 [7:0] Regsiter 3

New file: (expected output)
Code:
REG1 [7:0] Register 1
REGW 0001 1234
REG2 [7:0] Register 2
REGW 0002 5678
REG3 [7:0] Regsiter 3
REGW 0003 9ABC



REG1,REG2 and REG3 are the patterns I whish to GREP from the old file.
Thanks

Last edited by Scott; 05-27-2010 at 04:57 AM.. Reason: Code tags, please...
# 6  
Old 05-27-2010
try:

Code:
set IN_FILE = file.txt
set GREP_KEY = 'abcd'
set IN_LINE = "`grep ${GREP_KEY} ${IN_FILE}`"
echo "$IN_LINE"

This User Gave Thanks to clx For This Post:
# 7  
Old 05-27-2010
Again: Don't use C shell for scripting, it's a waste of time.

Csh Programming Considered Harmful
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sort a text file based on names in square brackets

Hi all, I have a text file similar to this: Text More text Etc Stuff That Is Needed Etc Etc This contains over 70 entries and each entry has several lines of text below the name in square brackets. (5 Replies)
Discussion started by: Scally
5 Replies

2. Shell Programming and Scripting

How to remove the text between all curly brackets from text file?

Hello experts, I have a text file with lot of curly brackets (both opening { & closing } ). I need to delete them alongwith the text between opening & closing brackets' pair. For ex: Input:- 59. Rh1 Qe4 {(Qf5-e4 Qd8-g8+ Kg6-f5 Qg8-h7+ Kf5-e5 Qh7-e7+ Ke5-f5 Qe7-d7+ Qe4-e6 Qd7-h7+ Qe6-g6... (6 Replies)
Discussion started by: prvnrk
6 Replies

3. Shell Programming and Scripting

Shell script to read specified value from file and echo to the same location to other file.

Hello. I want to to backup some "default:" values from a file do some other job and after restore that "default:" values back. The problem is that the source and destination file has a lot of default: strings in it but with different values... So.. Here is an example: A part of my source... (6 Replies)
Discussion started by: ausdim
6 Replies

4. Shell Programming and Scripting

Compare the value in between square brackets in file

I wanted to compare the value inside the Squre bracket after Colon ( : ) based on any value(seperated by or operator | ) inside the variable Thread and if match found then wnated to store in output file Input file : 20140320 00:08:43.918 INO 35] - Corporate hub is 20140320 00:08:43.918... (2 Replies)
Discussion started by: nes
2 Replies

5. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

6. Shell Programming and Scripting

parsing characters and number from a big file with brackets

I have a big file with many brackets () in it from which I need to parse number characters and numbers. Below is an example of my file 14 (((A__0:0.02,B__1:0.3)0:0.04,C__0:0.025)2:0.01),(D__0:0.00978,E__2:0.01031)1:0.00362; 15... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

7. UNIX for Dummies Questions & Answers

pls help, file name with brackets

Hi all, I have a number files like these below R1_970804_125318 R1_970804_125404(2) R1_980322_219282 R1_980301_210651(2) R1_980301_210651(3)and I'm trying to put file names into a string in order to perform some processings. FILES=`cat namelist.txt` for F in $FILES do ... ...... (10 Replies)
Discussion started by: sunnydanniel
10 Replies

8. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

9. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

10. Web Development

PHP echo everything including brackets and quotes

How can I print exactly what I want in between my quotes? I have xml that I want to echo exactly and it is not printing out the brackets and gets hung up at the "<?" and all that. Is there a way I can just say echo exactly between these quotes? (2 Replies)
Discussion started by: mainegate
2 Replies
Login or Register to Ask a Question