Read line based on character,


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read line based on character,
# 1  
Old 06-14-2010
Read line based on character,

Hi Experts,

I have called file1.txt contains below

Code:
CREATE TABLE "IHUBDEV2"."TLM_BREAK_RULES"
   (    "OID" VARCHAR2(32) NOT NULL ENABLE,
        "TLM_PAY_CLASS_OID" VARCHAR2(32) NOT NULL ENABLE,
        "PUNCHED_BREAKS" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE,
        "NORMAL_BREAKS" VARCHAR2(32),
        "MODIFIED_ON" DATE DEFAULT SYSDATE NOT NULL ENABLE,
         CONSTRAINT "PK_TLM_BREAK_RULES" PRIMARY KEY ("OID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "DATA1"  ENABLE,
         CONSTRAINT "FK1_TLM_BREAK_RULES" FOREIGN KEY ("TLM_PAY_CLASS_OID")
          REFERENCES "IHUBDEV2"."TLM_PAY_CLASS" ("OID") ENABLE
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "DATA1"

Now i want to read line based on ",". I want to treat as one line based on ",".

Please let me how to do it.

Thanks
Naree


Moderator's Comments:
Mod Comment Use code tags!

Last edited by zaxxon; 06-14-2010 at 07:49 AM.. Reason: code tags
# 2  
Old 06-14-2010
possibly easiest just to munge your file so it is in the format you want e.g.:

Code:
#   echo $(cat infile) | sed 's/,/,%/g' | tr "%" "\n"
CREATE TABLE "IHUBDEV2"."TLM_BREAK_RULES" ( "OID" VARCHAR2(32) NOT NULL ENABLE,
 "TLM_PAY_CLASS_OID" VARCHAR2(32) NOT NULL ENABLE,
 "PUNCHED_BREAKS" NUMBER(1,
0) DEFAULT 0 NOT NULL ENABLE,
 "NORMAL_BREAKS" VARCHAR2(32),
 "MODIFIED_ON" DATE DEFAULT SYSDATE NOT NULL ENABLE,
 CONSTRAINT "PK_TLM_BREAK_RULES" PRIMARY KEY ("OID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "DATA1" ENABLE,
 CONSTRAINT "FK1_TLM_BREAK_RULES" FOREIGN KEY ("TLM_PAY_CLASS_OID") REFERENCES "IHUBDEV2"."TLM_PAY_CLASS" ("OID") ENABLE ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "DATA1"

And then you can read line by line...

HTH
# 3  
Old 06-14-2010
I don't know if this is what you need:

Code:
tr -s "\n" " " < FICHERO_IN| awk -F, '{for (i=1;i<=NF;i++)print $i}'

# 4  
Old 06-14-2010
You already ignored 2 times infractions to use code tags. If you collect more infractions you will be banned when you reach 30 points. If you enjoy this forum, change your behaviour maybe and read&obeye the mails you get/got with these infractions.

Not sure if I totally understood; nevertheless with GNU sed:
Code:
$> sed -e :a -e '/,$/ {N; s/ *\n */ /}; ta' infile
CREATE TABLE "IHUBDEV2"."TLM_BREAK_RULES"
   (    "OID" VARCHAR2(32) NOT NULL ENABLE, "TLM_PAY_CLASS_OID" VARCHAR2(32) NOT NULL ENABLE, "PUNCHED_BREAKS" NUMBER(1,0) DEFAULT 0 NOT NULL ENABLE, "NORMAL_BREAKS" VARCHAR2(32), "MODIFIED_ON" DATE DEFAULT SYSDATE NOT NULL ENABLE, CONSTRAINT "PK_TLM_BREAK_RULES" PRIMARY KEY ("OID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "DATA1"  ENABLE, CONSTRAINT "FK1_TLM_BREAK_RULES" FOREIGN KEY ("TLM_PAY_CLASS_OID")
          REFERENCES "IHUBDEV2"."TLM_PAY_CLASS" ("OID") ENABLE
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "DATA1"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

How to read the nth character from the line.?

I have Index Line and I tried to get the 9th character from the file and to check the character is "|" or not. Shell Scripting. Sample Index file. "91799489|K8E|188.004.A.917994892.1099R.c.01.pdf|2013|10/15/2014|002|B|C|C"... (3 Replies)
Discussion started by: pavand
3 Replies

2. UNIX for Beginners Questions & Answers

Append each line based upon the character size

I have a huge file which contains multiple lines. It need to check whether character length is not more than 255 each line. If its not then it should remove the character up to column. I have described in the output below. If its more than that the next line should start with call but if the... (1 Reply)
Discussion started by: JoshvaPeter
1 Replies

3. UNIX for Beginners Questions & Answers

Cut each line based on the character size

Hello All, I have a file which contain below lines. The starting word of each line is call and the end line is semi colon. I need to find the character size of each line and then move it to a file. If the character size is more than 255 then I need to push that line to a next file and I need... (6 Replies)
Discussion started by: JoshvaPeter
6 Replies

4. Shell Programming and Scripting

Read character by character in line in which space is also included

Hi friend, I have one file , and i want to read that file character by character. I need this script in ksh. while using read option with -n1 am getting error. while read -n1 c read has bad option And if i am using below script, then if in a line has space like this ( Pallvi mahajan)... (10 Replies)
Discussion started by: pallvi_mahajan
10 Replies

5. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

6. Shell Programming and Scripting

Delete line based on count of specific character

I'm looking for what I hope might be a one liner along these lines: sed '/a line with more than 3 pipes in it/d' I know how to get the pipe count in a string and store it in a variable, but I'm greedy enough to hope that it's possible via regex in the /.../d context. Am I asking too much? ... (5 Replies)
Discussion started by: tiggyboo
5 Replies

7. Shell Programming and Scripting

Read file from nth line to specific character

Hi, I want to read the file from nth line (where n is an integer) to until I encounter @ char. Can any one please help me how to do this? Thanks. (3 Replies)
Discussion started by: laalesh
3 Replies

8. Shell Programming and Scripting

How to read one character form each line of the file?

Hi, Maybe this iscorrect forum for my question... I should read one character at a fixed position from each line of the file. So how ??? should be substituted in the code below: while read line ; do single_char=`???` echo "$single_char" done < $input_file OK...I did get an... (0 Replies)
Discussion started by: arsii
0 Replies

9. Shell Programming and Scripting

Read First Character of Each Line in File

I need a better way to read the first character of each line in a file and check if it equals the special character ¤. This character tells me where there is a break in the reports. The file has over 500,000 lines. Currently, this is my code - if ] I am using Korn Shell as a scripting... (7 Replies)
Discussion started by: azelinsk
7 Replies

10. UNIX for Dummies Questions & Answers

delete a line based on first character of the line

Hi, I need to delete all lines in a file which starts with "|" character. Can some one assist me? Thanks (2 Replies)
Discussion started by: borncrazy
2 Replies
Login or Register to Ask a Question