Copying of multiple columns of one table to another by mapping with particular strings.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying of multiple columns of one table to another by mapping with particular strings.
# 15  
Old 04-12-2011
Hi dsh007,

This is not the only way, but...you need to do the following:
  • go to folder with your csv files
  • create a file called names.awk with this code in:
Code:
BEGIN{FS=","}
NR==1 {
    for(i=1;i<=NF;i++) {
        if($i~/NAME/ || $i=="STLC") {
            cols[i]=i
            head = head==""? $i : head","$i
        }
    } 
    print head
    next
}
{
    for (item in cols) {
        row = row==""? $item : row","$item
    }
    print row
    row = ""
}

  • type this script, as given by @michaelrozar17 into your shell:
Code:
for file in `ls *.csv`
do
    awk -f names.awk $file > ${file%.*}-new.${file#*.}
done

Try this, if it does not work post back what you have typed and the error message.

Good luck.Smilie
# 16  
Old 04-12-2011
it is giving the same Syntax error.
Ya i know there are many way of solving the problem, can you suggest me some other way.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Mapping the values of ids of two columns of file1 from file2

I have of two space separated files: ==> File1 <== PT|np_496075.1 st|K92748.1 st|K89648.1 PT|np_001300561.1 PT|np_497284.1 st|K90752.1 st|K90279.1 PT|np_740775.1 PT|np_497749.1 st|K90752.1 st|K92038.1 PT|np_490856.1 PT|np_497284.1 st|K90752.1 st|K88095.1 PT|np_494764.1 ==> File 2 <==... (2 Replies)
Discussion started by: sammy777888
2 Replies

2. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

3. Programming

awk to count occurrence of strings and loop for multiple columns

Hi all, If i would like to process a file input as below: col1 col2 col3 ...col100 1 A C E A ... 3 D E G A 5 T T A A 6 D C A G how can i perform a for loop to count the occurences of letters in each column? (just like uniq -c ) in every column. on top of that, i would also like... (8 Replies)
Discussion started by: iling14
8 Replies

4. UNIX and Linux Applications

Help in copying table structure to another table with constraints in Oracle

hi, i need to copy one table with data into another table, right now am using create table table1 as select * from table2 i want the constraints of table1 to be copied to table2 also , can anyone give me some solution to copy the constraints also, now am using oracle 10.2.0.3.0... (1 Reply)
Discussion started by: senkerth
1 Replies

5. Shell Programming and Scripting

Merge left hand strings mapping to different right hand strings

Hello, I am working on an Urdu to Hindi dictionary which has the following structure: a=b a=c n=d n=q and so on. i.e. Headword separated from gloss by a = I am giving below a live sample بتا=बता بتا=बित्ता بتا=बुत्ता بتان=बतान بتان=बितान بتانا=बिताना I need the following... (3 Replies)
Discussion started by: gimley
3 Replies

6. Shell Programming and Scripting

Copying lines between two strings

Hello All, I want to copy some lines from one file to other with following condition. Only lines between two specified strings should copy. Example :- "My First String " Some_Other_String .... Some_Other_String .... Some_Other_String .... "My Second String" So only... (5 Replies)
Discussion started by: anand.shah
5 Replies

7. Shell Programming and Scripting

Creating unique mapping from multiple mapping

Hello, I do not know if this is the right title to use. I have a large dictionary database which has the following structure: where a b c d e are in English and p q r s t are in a target language., the two separated by the delimiter =. What I am looking for is a perl script which will take... (5 Replies)
Discussion started by: gimley
5 Replies

8. Shell Programming and Scripting

Numbering, copying and replacing strings

hello everybody there, I'm a new bash shell programmer and I'm dealing with a problem. To start, I have a file with a number of string lines which may contain a particular string or not. I have to write a code that identifies the line containing one particular string and keeps it, but also writes... (10 Replies)
Discussion started by: leaf
10 Replies

9. Shell Programming and Scripting

Copying and pasting columns from different files

hi all, first time posting, hoping i can get some help on this. I have about 80 text files containing text in this format: # Rg Mass Density Rcm-x Rcm-y Area Rsph/sqrt(2) # == ==== ======= ===== ===== ==== ... (9 Replies)
Discussion started by: Arlamos
9 Replies

10. Shell Programming and Scripting

copying strings...

hey i want to know the unix command for copying 1 string to another and allso adding a third string to the result. for eg: a b="nbno" c="uioio" i want to copy contents of b to a and the append the contents of c to the contents of a and the result shud be in string a (1 Reply)
Discussion started by: priya_9patil
1 Replies
Login or Register to Ask a Question