Sponsored Content
Full Discussion: rearrange a file
Top Forums Shell Programming and Scripting rearrange a file Post 302276696 by Panos1962 on Wednesday 14th of January 2009 11:35:26 AM
Old 01-14-2009
It's easy for awk

Code:
BEGIN {
    FS = ","
    tmp1 = "/tmp/" PROCINFO["pid"] ".1"
    tmp2 = "/tmp/" PROCINFO["pid"] ".2"
}

{
    if (another_line) {
        printf "," >>tmp1
        printf "," >>tmp2
    }
    else
        another_line = 1

    printf $NF >>tmp1
    printf $1 >>tmp2
}

END {
    close(tmp1)
    close(tmp2)
    if (another_line) {
        system("cat " tmp1)
        print ""
        system("cat " tmp2)
        print ""
    }

    system("rm -f " tmp1)
    system("rm -f " tmp2)
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Rearrange bytes within a txt file

I have a text file with a very long list of dates, one date per line. Each date is in the same format yyyymmdd. I need the dates to be in mmddyyyy format. This is part of a larger tcsh shell script. I am just learning unix and came up with: for each line in file for each character in... (4 Replies)
Discussion started by: yankee428
4 Replies

2. Shell Programming and Scripting

Need help with a script to rearrange columns

I have a file that is semi-colon delimited and the column headers are always the same but the column number is totally random each time this file is generated. I don't have the skills to make a script for this so maybe someone can help. I would like to be able to take this file which has over... (11 Replies)
Discussion started by: n3al10
11 Replies

3. Shell Programming and Scripting

rearrange info of file in a "table"

Please I need to rearrange data acquired by USB port from a sensor network. The information is mixed and I need to convert it into a kind of table. This is my input file: Node 4D5A joined Temperature: 27,5 Humidity: 40 Dew Point: 23 No motion detected LUX: 389 Temperature: 28 Humidity: 41... (5 Replies)
Discussion started by: csecnarf
5 Replies

4. UNIX for Dummies Questions & Answers

Help rearrange the content of the file.

Hi all, I need to rearrange the content of the file. I need to move line 1 to 4, 2 to 3, 3 to 2, and 4 to 1. IPlease help. I was thinking about using head and tail command. Here is the original file. aa bb cc dd Here is what I need it to be. dd cc bb aa Thanks. (6 Replies)
Discussion started by: sirrtuan
6 Replies

5. Shell Programming and Scripting

Rearrange the text file

Gents, I have a large file and each line of the file contains more than 200 bytes.Please let me a way to have the new line to start when the word "FIT" appears. I was trialling with 'tr' command but i am not sure how to get it based on bytes and so it wasn't working... Current... (3 Replies)
Discussion started by: appu2176
3 Replies

6. Shell Programming and Scripting

Using awk to rearrange fields

Hi, I am required to arrange columns of a file i.e make the 15th column into the 1st column. I am doing awk 'begin {fs=ofs=","} {print $15,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14}' ad.data>ad.csv the problem is that column 15 gets to column 1 but it is not comma separated with the... (10 Replies)
Discussion started by: seddoubt
10 Replies

7. UNIX for Dummies Questions & Answers

Transpose matrix, and rearrange columns common with another file

This is my first post, I apologize if I have broken rules. Some assistance with the following will be very helpful. I have a couple of files, both should ultimately have common columns only, arranged in the same order. This file needs to be transposed, to bring the rows to columns ... (2 Replies)
Discussion started by: abh.kumar
2 Replies

8. Shell Programming and Scripting

Rearrange a file (2000 base64 strings in 1 row into 1 string by rows)

I have 1 row which contains abouts 20000 base64 string. e.g: /p4bdllBS8qcvW/69GUYej8nEv6gwt7UAYl0g==WZdjwTUQX9UEKsT/zWaZdQ==uI would like rearrange this file by base64 strings. So the output should be this ( 1 string in 1 row): 69GUYej8nEv6gwt7UAYl0g== WZdjwTUQX9UEKsT/zWaZdQ==How could I do... (4 Replies)
Discussion started by: freeroute
4 Replies

9. Shell Programming and Scripting

A cleaner way to rearrange column

Hello, I have some tab delimited text data, index name chg_p chg_m 1 name,1 1 0 2 name,2 1 1 3 name,3 1 0 4 name,4 1 0 5 name,5 1 1 I need to duplicate the "index" column, call it "id" and insert it after the... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

10. Shell Programming and Scripting

Rearrange fields of delimited text file

I want to rearrange the fields of delimited text file after sorting first line (only): input file: a_13;a_2;a_1;a_10 13;2;1;10 the result should be: a_1;a_2;a_10;a_13 1;2;10;13 any help would be appreciated andy (20 Replies)
Discussion started by: andy2000
20 Replies
psiclean(1)															       psiclean(1)

NAME
psiclean - delete files in the PSI temporary directories DESCRIPTION
The psiclean command finds a job name by scanning the input file for a keyword assignment of the form DEFAULT:FILES:DEFAULT:NAME = string It then goes through all of the machine's temporary directories and deletes all files of the form string.*. In previous versions of psi- clean , temporary directories were assumed to be of the form /tmp[0-9]/$user In this version of psiclean , we get the names of the temporary directories from the user input file by looking for volume paths of the form DEFAULT:FILES:DEFAULT:VOLUMEi = string It is essential that users see to the removal of their scratch files as soon as their job completes, because temporary directories are usu- ally a shared resource and there is not necessarily an automatic way for files to be deleted from these areas. Thus, the last command run after a job has finished should be the psiclean command. The user must take care to follow certain conventions when choosing filenames. Any files which are to be kept after a job completes should not be kept in the default temporary directories. The FILES input must be used to specify other locations for the specific files which are to be kept. psiclean will ignore files which are specifically listed by number (e.g., PSIF_CHKPT ) in the FILES section. Files which are not needed after the run should use the default path given in the input file. Otherwise, these files will remain on the system and will impede other jobs. EXAMPLE
Suppose the PSI temporary directories contained the following subdirectories and files: /tmp1/cpuhog: -rw-r--r-- 1 cpuhog 14492 Jun 11 16:48 dicubane.30 -rw-r--r-- 1 cpuhog 187320 Jun 8 17:20 diketene.34 -rw-r--r-- 1 cpuhog 16384 Jun 7 19:17 o4big.30 -rw-r--r-- 1 cpuhog 16384 Jun 7 19:17 o4.30 -rw-r--r-- 1 cpuhog 974848 Jun 7 18:41 o4.34 /tmp2/cpuhog: -rw-r--r-- 1 cpuhog 14492 Jun 11 16:48 dicubane.30 -rw-r--r-- 1 cpuhog 187320 Jun 8 17:20 diketene.34 -rw-r--r-- 1 cpuhog 10904 Jun 7 18:50 o4big.30 -rw-r--r-- 1 cpuhog 10904 Jun 7 18:50 o4.30 -rw-r--r-- 1 cpuhog 973752 Jun 7 18:41 o4.34 /tmp3/cpuhog: -rw-r--r-- 1 cpuhog 14492 Jun 11 16:48 dicubane.30 -rw-r--r-- 1 cpuhog 187320 Jun 8 17:20 diketene.34 -rw-r--r-- 1 cpuhog 8192 Jun 7 19:17 o4big.30 -rw-r--r-- 1 cpuhog 8192 Jun 7 19:17 o4.30 -rw-r--r-- 1 cpuhog 966656 Jun 7 18:41 o4.34 Let's also say that the user cpuhog is in a directory which contains an input file which has the following line in it: DEFAULT:FILES:DEFAULT:NAME = "o4" If the user cpuhog now executes the psiclean command, then the o4 files in the temporary directories would be deleted, leaving the follow- ing files: /tmp1/cpuhog: -rw-r--r-- 1 cpuhog 14492 Jun 11 16:48 dicubane.30 -rw-r--r-- 1 cpuhog 187320 Jun 8 17:20 diketene.34 -rw-r--r-- 1 cpuhog 16384 Jun 7 19:17 o4big.30 /tmp2/cpuhog: -rw-r--r-- 1 cpuhog 14492 Jun 11 16:48 dicubane.30 -rw-r--r-- 1 cpuhog 187320 Jun 8 17:20 diketene.34 -rw-r--r-- 1 cpuhog 10904 Jun 7 18:50 o4big.30 /tmp3/cpuhog: -rw-r--r-- 1 cpuhog 14492 Jun 11 16:48 dicubane.30 -rw-r--r-- 1 cpuhog 187320 Jun 8 17:20 diketene.34 -rw-r--r-- 1 cpuhog 8192 Jun 7 19:17 o4big.30 AUTHOR
C. David Sherrill <sherrill@alum.mit.edu> Psi Version 3.0 29 July, 1999 psiclean(1)
All times are GMT -4. The time now is 12:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy