Formating questions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formating questions
# 1  
Old 01-22-2014
Formating questions

Hi,

I have a data as follows in some files, i want to change CHAR(2-20) to VARCHAR(2-20). I should not touch any line with CHAR(1)

Example:

Input:
Code:
     cur_rev_stage_cd CHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
      prev_rev_stage_cd CHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
      revrec_prcs_cd CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC,
      revrec_cur_rev_stage_cd CHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
      revrec_prev_rev_stage_cd CHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
      svc_base_cd CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC,
      pkging_type_cd CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC,
      bus_tran_type_cd CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
      dvc_nm CHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
      cust_intln_cd CHAR(3) CHARACTER SET LATIN NOT CASESPECIFIC,
      cash_only_flg CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
      shpmt_type_cd CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,


Result should be given below:
Code:
      cur_rev_stage_cd VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
      prev_rev_stage_cd VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
      revrec_prcs_cd VARCHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC,
      revrec_cur_rev_stage_cd VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
      revrec_prev_rev_stage_cd VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
      svc_base_cd VARCHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC,
      pkging_type_cd VARCHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC,
      bus_tran_type_cd CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
      dvc_nm VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
      cust_intln_cd VARCHAR(3) CHARACTER SET LATIN NOT CASESPECIFIC,
      cash_only_flg CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
      shpmt_type_cd CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,


Last edited by Corona688; 01-22-2014 at 12:47 PM..
# 2  
Old 01-22-2014
Could this ?

Code:
$ awk -F'[(|)]' '$2>=2 && $2<=20{gsub(/CHAR/,"VARCHAR",$1);$1=$1"("$2")";$2=""}1'  file


Last edited by Akshay Hegde; 01-22-2014 at 12:56 PM.. Reason: editing
# 3  
Old 01-22-2014
Please use code tags as required by forum rules!

Try this
Code:
awk '{gsub (/CHAR\([^1]|[12][0-9]\)/,"VAR&")}1' file

# 4  
Old 01-22-2014
Hi Rudi,

Thank you for your quick response.

We have some data as CHAR(10) and CHAR(15) as well in the data. We can to change that also VARCHAR(10) and VARCHAR(15) respectively. Kindly suggest ?

Regards,
Srikanth

---------- Post updated at 10:37 PM ---------- Previous update was at 10:33 PM ----------

If i use below command:

Code:
awk '{gsub (/CHAR\([^1]|[12][0-9]\)/,"VAR&")}1' file

Its changing

Code:
pkg_trkng_uniq_id CHAR(VAR10) CHARACTER SET LATIN NOT CASESPECIFIC,

But i want it as follows:

Code:
pkg_trkng_uniq_id VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC,

Regards,
Srikanth

Last edited by Corona688; 01-22-2014 at 01:15 PM..
# 5  
Old 01-22-2014
I thought I had tested that as well. Rats! Try this:
Code:
awk '{gsub (/CHAR\(([^1]|[12][0-9])\)/,"VAR&")}1' file
cur_rev_stage_cd VARCHAR(15) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
prev_rev_stage_cd VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
revrec_prcs_cd VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC,
revrec_cur_rev_stage_cd VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
revrec_prev_rev_stage_cd VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
svc_base_cd VARCHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC,
pkging_type_cd VARCHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC,
bus_tran_type_cd CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
dvc_nm VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
cust_intln_cd VARCHAR(3) CHARACTER SET LATIN NOT CASESPECIFIC,
cash_only_flg CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,
shpmt_type_cd CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC,

This User Gave Thanks to RudiC For This Post:
# 6  
Old 01-22-2014
@srikanth38

You didn't try #2 ?
Assumed that field1 contains only CHAR where Field Separator is (|)

if only CHAR(10)
Code:
$ awk -F'[(|)]' '$2==10{gsub(/CHAR/,"VARCHAR",$1);$1=$1"("$2")";$2=""}1' file

# 7  
Old 01-22-2014
Thank you Rudi. Appriciate you help. It worked fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

File formating help

Hi all, I am having the file below I need that as below Thanks, Arun (12 Replies)
Discussion started by: arunkumar_mca
12 Replies

2. UNIX for Dummies Questions & Answers

Help with formating when using mailx

Hi I am a newbie here. I tried searching for the solution but I guess I either didn't find it or there hasn't been one posted. my problem is I spooled the results of a query into a .txt file. When I cat the file the formating looks great. All the columns are aligned. However once I mailx the... (2 Replies)
Discussion started by: RB26DETT
2 Replies

3. Homework & Coursework Questions

Print questions from a questions folder in a sequential order

1.) I am to write scripts that will be phasetest folder in the home directory. 2.) The folder should have a set-up,phase and display files I have written a small script which i used to check for the existing users and their password. What I need help with: I have a set of questions in a... (19 Replies)
Discussion started by: moraks007
19 Replies

4. Shell Programming and Scripting

Formating output

Hello Team i have a file with following data (as columns). I need implement a syntax like below for altering table ALTER TABLE1 TABLENAME ADD COLUMN COL1 CHAR(5) NOT NULL WITH DEFAULT ADD COLUMN COL2 CHAR(5) .. .. ADD COLUMN COLn CHAR(5) NOT NULL... (1 Reply)
Discussion started by: rocking77
1 Replies

5. Shell Programming and Scripting

Text formating

Dear all I had input file as mention below and want op as mention. Kindly let me knw possible ways. Regards Jaydeep INPUT: RXOTX-48-1 2A 34 2B 35 RXOTX-499-2 2C 32 RXOTX-4-1 2D 23 OUTPUT: (3 Replies)
Discussion started by: jaydeep_sadaria
3 Replies

6. Shell Programming and Scripting

formating output

Hi all, I want to start a new topic on this matter I have this script, #!perl use strict; use warnings; use Data::Dumper; open my $log, '>', 'log-external.txt' or die "Could not open log: $!"; print $log "Subnet,Static,DHCP,Unused\n"; open my $dump, '>', 'dump.log' or die... (2 Replies)
Discussion started by: richsark
2 Replies

7. Shell Programming and Scripting

Output formating

Dear All I am stuck in one problem. Kindly help me. I am taking below mention file as input file and want some op file as mention below. Kindly send me all possible suggestion and query. Thnaks Jaydeep bELOW IS THE INPUT FILE: *** Connected to BSCANGR ***... (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies

8. Shell Programming and Scripting

formating date

Guys I have a date value like this in a table -> 2006-12-29 12:57:08(data type varchar2(25)) I am trying to subtract this column from sysdate. I am unable to do that. can u guys suggest me a way to do this.. (2 Replies)
Discussion started by: ragha81
2 Replies

9. UNIX for Dummies Questions & Answers

Formating in Echo?

Hi, In my code: echo " Field1 " " Filed2 " " Filed3 " >> $myfile echo "--------" "------- " "--------">> $myfile echo $value1 $value2 $value3 >> $myfile echo $value1 $value2 $value3 >> $myfile echo $value1 $value2 $value3 >> $myfile My file... (4 Replies)
Discussion started by: redlotus72
4 Replies

10. UNIX for Dummies Questions & Answers

Disk formating

i have to repartition some of my filesystems ... I have just one HDD .... df -k gives this :- Filesystem kbytes used avail capacity Mounted on /dev/dsk/c0t0d0s0 830107 45532 726468 6% / /dev/dsk/c0t0d0s1 1987399 785728 1142050 41% /usr /proc ... (1 Reply)
Discussion started by: DPAI
1 Replies
Login or Register to Ask a Question