error while extracting a line from a file based on identifier


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error while extracting a line from a file based on identifier
# 1  
Old 12-06-2011
error while extracting a line from a file based on identifier

here is the content of input file
Code:
CREATE TABLE `bla bla bla` (
  `allianceSiteId` int(11) DEFAULT NULL,
  `trunkGroupsId` int(11) DEFAULT NULL,
  `lastModified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY `allianceSiteId` (`allianceSiteId`,`trunkGroupsId`)
)

here is the part of the code whihc is inside a while loop reading a file
Code:
echo "whole line is : $line1"
 if  [[ `expr match "$line1" ".*CREATE TABLE.*"` != "0" ]]
 then
                firstword="$line1"
                fi
                echo "firstword : $firstword"
                lastword=") ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"
                echo "lastword : $lastword"

here is the part of output

Code:
firstword : CREATE TABLE `AllianceSiteTrunkGroupTrunkGroupsMap` (
lastword : ) ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
whole line is : )
expr: syntax error
firstword : )
lastword : ) ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

my doubt is why am i getting "expr: syntax error"... if the $line1 has ) it should not go inside if statement... what is the solution...
# 2  
Old 12-06-2011
good to use

if grep -q <search text> <<<"$line"
This User Gave Thanks to tarun_agrawal For This Post:
# 3  
Old 12-06-2011
what is the exact syntax...
if grep -q <CREATE TABLE> <<<"$line" .? is this correct... cause i am getting syntax error... does it need to be in double quotes.. the error is like this

Code:
./damp: line 112: syntax error near unexpected token `<<<'
./damp: line 112: `if grep -q <"CREATE TABLE"> <<<"$line"'

# 4  
Old 12-06-2011
if grep -q "CREATE TABLE" <<<"$line"
then
...
fi.
This User Gave Thanks to tarun_agrawal For This Post:
# 5  
Old 12-06-2011
thanks it worked... :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting values based on line-column numbers from multiple text files

Dear All, I have to solve the following problems with multiple tab-separated text file but I don't know how. Any help would be greatly appreciated. I have access to Linux mint (but not as a professional). I have multiple tab-delimited files with the following structure: file1: 1 44 2 ... (5 Replies)
Discussion started by: Bastami
5 Replies

2. Shell Programming and Scripting

To cut a string based on last index of identifier

here below is sample string null pointer dereference of 'resourceList' where null is returned from a method/opt/bld/fetch/ds/interzone/notification/LocalLineStatusNotificationListener.java:79 null pointer dereference of 'reList' where null is returned from a... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

4. Shell Programming and Scripting

Extracting few lines from a file based on identifiers dynamically

i have something like this in a file called mysqldump.sql -- -- Table structure for table `Table11` -- DROP TABLE IF EXISTS `Table11`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Table11` ( `id` int(11) NOT NULL... (14 Replies)
Discussion started by: vivek d r
14 Replies

5. Shell Programming and Scripting

Extracting data based on the list file

Hi there, Can you help. I need to extract data based on the list file(list.txt) from item.txt as shown below. Please note the actual files are enormous in size. Thank you. item.txt nokia1100 123,000 nokia2100 66,000 samsung123 11,000 samsung456 23,000 iphone432 234,000... (12 Replies)
Discussion started by: shtobias
12 Replies

6. Shell Programming and Scripting

Extracting a portion of a data file with identifier

Hi, I do have a TAB delimted text file with the following format. 1 (- identifier of each group. this text is not present in the file only number) 1 3 4 65 56 WERTF 2 3 4 56 56 GHTYHU 3 3 5 64 23 VMFKLG 2 1 3 4 65 56 DGTEYDH 2 3 4 56 56 FJJJCKC 3 3 5 64 23 FNNNCHD 3 1 3 4 65 56 JDHJDH... (9 Replies)
Discussion started by: Lucky Ali
9 Replies

7. Shell Programming and Scripting

Extracting lines in file based on time

Hi, anyone has any ideas on how do we extract lines from a file with format similiar to this: (based on current time) Jun 18 00:16:50 .......... ............. ............ Jun 18 00:17:59 .......... ............. ............ Jun 18 01:17:20 .......... ............. ............ Jun 18... (5 Replies)
Discussion started by: faelric
5 Replies

8. Shell Programming and Scripting

merging column from two files based on identifier

Hi, I have two files consisting of two columns. So I want to merge column 2 if column 1 is the same. So heres an example of what I mean. FILE1 driver 444 car 333 hat 222 FILE2 driver 333 car 666 hat 999 So I want to merge the column 2's together so... (4 Replies)
Discussion started by: phil_heath
4 Replies

9. Shell Programming and Scripting

extracting a line based on line number

i want to cut all the entries from the /etc/passwd file in which the uid is> 500 for this i was writing this ,m quiet new to all this.. scripting but on the 6th n 8th line ,, i hav to specify a line number .. to get the commnd working .. but i want to use variable i instead of that ,,... (2 Replies)
Discussion started by: narendra.pant
2 Replies

10. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies
Login or Register to Ask a Question