Sponsored Content
Top Forums Shell Programming and Scripting Relocation strings using awk/sed from a index file Post 302972761 by jypark22 on Tuesday 10th of May 2016 01:09:53 PM
Old 05-10-2016
Relocation strings using awk/sed from a index file

Hi All,

I'd always appreciate all helps from this website. I would like to relocate strings based on the index number from an index file.


Index numbers are shown on the first column in the index file (index.txt) and I would like to relocate "path" based on index numbers. Paths are placed in the same row if the index number is the same. For example, there are two zeros so path_sparc_ifu_dec_in_3826 is placed on the first row and path_sparc_ifu_dec_in_4349 is placed on the first row and next to path_sparc_ifu_dec_in_3826.

index.txt:

Code:
     0        path_sparc_ifu_dec_in_3826  str    DR     -         -
     0        path_sparc_ifu_dec_in_4349  stf    DR     -         -
     1        path_sparc_ifu_dec_in_2374  stf    DR     -         -
     1        path_sparc_ifu_dec_in_4011  stf    DR     -         -
     2        path_sparc_ifu_dec_in_3078  stf    DR     -         -

However, strings are written in another file (source.txt) and each "path" has four lines of strings.

source.txt:

Code:
    path_sparc_ifu_dec_in_3826
    dtu_inst_d[14]
    dec_fcl_rdsr_sel_pc_d
    0.8664
    path_sparc_ifu_dec_in_4349
    dtu_inst_d[18]
    dec_swl_rdsr_sel_thr_d
    0.795429
    path_sparc_ifu_dec_in_2374
    dtu_inst_d[13]
    dec_dcl_cctype_d[2]
    0.938914
    path_sparc_ifu_dec_in_4011
    dtu_inst_d[13]
    ifu_exu_useimm_d
    0.843643
    path_sparc_ifu_dec_in_3078
    dtu_inst_d[12]
    ifu_exu_shiftop_d[2]
    0.915818

The desired output is:

Code:
    path_sparc_ifu_dec_in_3826	    path_sparc_ifu_dec_in_4349
    dtu_inst_d[14]	    dtu_inst_d[18]
    dec_fcl_rdsr_sel_pc_d	    dec_swl_rdsr_sel_thr_d
    0.8664	0.795429
    path_sparc_ifu_dec_in_2374	    path_sparc_ifu_dec_in_4011
    dtu_inst_d[13]	    dtu_inst_d[13]
    dec_dcl_cctype_d[2]	    ifu_exu_useimm_d
    0.938914	0.843643
    path_sparc_ifu_dec_in_3078	
    dtu_inst_d[12]	
    ifu_exu_shiftop_d[2]	
    0.915818

My idea is that (1)combining two files first and (2) relocate path info using the index number, but I don't know how to do this work. Probably, sed/awk is an appropriate language.

Any help is appreciated.

Best,

Jaeyoung
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

(awk) compare files in dir with an index file

Using awk I have an index file which has been seperated into 5 fields. The first field contains file names. What I need to do is check to see if a file exists in my current directory that is not in the first field of my index file. If its not i print out a message. Please help! (4 Replies)
Discussion started by: xthexonex
4 Replies

2. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

3. UNIX for Dummies Questions & Answers

Using awk/sed to extract text between Strings

Dear Unix Gurus, I've got a data file with a few hundred lines (see truncated sample)... BEGIN_SCAN1 TASK_NAME=LA48 PDD Profiles PROGRAM=ArrayScan 1.00 21.220E+00 2.00 21.280E+00 END_DATA END_SCAN1 BEGIN_SCAN2 TASK_NAME=LA48 PDD Profiles 194.00 2.1870E+00 ... (5 Replies)
Discussion started by: tintin72
5 Replies

4. Shell Programming and Scripting

Replace Strings with sed or awk

Hello i need some help with the usage of sed. Situation : 2 textfiles, file.in , file.out In the first textfile which is called file.in are the words for the substitution. Every word is in a new-line like : Firstsub Secondsub Thridsub ... In the second textflie wich is called file.out is... (5 Replies)
Discussion started by: Kingbruce
5 Replies

5. Shell Programming and Scripting

awk extract certain digits from file with index substr

I would like to extract a digit from $0 starting 2,30 to 3,99 or 2.30 to 3.99 Can somebody fix this? awk --re-interval '{if($0 ~ /{1}{2}/) {print FILENAME, substr($0,index($0,/{1}{2}/) , 4)}}'input abcdefg sdlfkj 3,29 g. lasdfj alsdfjasl 2.86 gr. slkjds sldkd lskdjfsl sdfkj kdjlksj 3,34 g... (4 Replies)
Discussion started by: sdf
4 Replies

6. Shell Programming and Scripting

awk or sed script to remove strings

Below am trying to separate FA-7A:1, In output file it should display 7A 1 Command am using Gives same output as below format: 22B7 10000000c9720873 0 22B7 10000000c95d5d8b 0 22BB 10000000c97843a2 0 22BB 10000000c975adbd 0 Not showing FA ports as required format... (5 Replies)
Discussion started by: aix_admin_007
5 Replies

7. Programming

How to replace the complex strings from a file using sed or awk?

Dear All, I am having a requirement to find the difference between 2 files and generate a discrepancy report out of it as an html page. I prefer using diff -y file1 file2 since it gives user friendly layout to know any discrepancy in the record and unique records among the 2 file. Here's how it... (12 Replies)
Discussion started by: Badhrish
12 Replies

8. Shell Programming and Scripting

Relocation strings

Hi all, I would like to relocate strings based on the index number. Index numbers are shown on the first column, the strings are shown on the second column. 1 path_sparc_ifu_dec_104 1 path_sparc_ifu_dec_105 2 path_sparc_ifu_dec_63 2 ... (3 Replies)
Discussion started by: jypark22
3 Replies

9. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

10. Shell Programming and Scripting

Adding sequential index to duplicate strings

I have a text file in the following format >Homo sapiens KQKCLYNLPFKRNLEGCRERCSLVIQIPRCCKGYFGRDCQACPGGPDAPCNNRGVCLDQY SATGECKCNTGFNGTACEMCWPGRFGPDCLPCGCSDHGQCDDGITGSGQCLCETGWTGPS CDTQAVLPAVCTPPCSAHATCKENNTCECNLDYEGDGITCTVVDFCKQDNGGCAKVARCS... (2 Replies)
Discussion started by: jerrild
2 Replies
funindex(1)							SAORD Documentation						       funindex(1)

NAME
funindex - create an index for a column of a FITS binary table SYNOPSIS
funindex <switches> <iname> [oname] OPTIONS
NB: these options are not compatible with Funtools processing. Please use the defaults instead. -c # compress output using gzip" -a # ASCII output, ignore -c (default: FITS table)" -f # FITS table output (default: FITS table)" -l # long output, i.e. with key value(s) (default: long)" -s # short output, i.e. no key value(s) (default: long)" DESCRIPTION
The funindex script creates an index for the specified column (key) by running funtable -s (sort) and then saving the column value and the record number for each sorted row. This index will be used automatically by funtools filtering of that column, provided the index file's modification date is later than that of the data file. The first required argument is the name of the FITS binary table to index. Please note that text files cannot be indexed at this time. The second required argument is the column (key) name to index. While multiple keys can be specified in principle, the funtools index process- ing assume a single key and will not recognize files containing multiple keys. By default, the output index file name is [root]_[key].idx, where [root] is the root of the input file. Funtools looks for this specific file name when deciding whether to use an index for faster filtering. Therefore, the optional third argument (output file name) should not be used for funtools processing. For example, to create an index on column Y for a given FITS file, use: funindex foo.fits Y This will generate an index named foo_y.idx, which will be used by funtools for filters involving the Y column. SEE ALSO
See funtools(7) for a list of Funtools help pages version 1.4.2 January 2, 2008 funindex(1)
All times are GMT -4. The time now is 12:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy