Sponsored Content
Top Forums Shell Programming and Scripting Help with regular command creation for editor vi Post 302998750 by Don Cragun on Tuesday 6th of June 2017 05:14:22 PM
Old 06-06-2017
To rearrange the first five fields of all lines in a file named file that contain five or more <hyphen> separated fields and leave other lines unchanged, you could use:
Code:
sed 's/\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)/\3-\2-\1-\5-\4/' file

Note that BRE back references count fields starting at 1, not 0.

If you are in vi with file currently loaded into the editing buffer and want to make that change to all lines in the buffer that match that pattern, the command to type into vi would be:
Code:
:g/\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)-\([^-]*\)/s//\3-\2-\1-\5-\4/

If this isn't what you want, you need to write a much clearer statement of your requirements, tell us what operating system you're using, what shell you're using, where these strings are located, where you want the results to be placed, etc.

Note, however, that the above code will NOT change "duck" to "duk" while it rearranges the fields. If you really want to do that, you'll need to further explain the logic used to determine which letters to drop from which fields while rearranging fields.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

vi editor - ex Command help

:1,10 s/yes/no/g this ex command will substitute yes with no everytime it is found within the first 10 lines of the file. :s/yes/no/g this ex command will substitute yes with no everytime it is found for the line where the cursor is on my question is how could this substitution be... (4 Replies)
Discussion started by: theDirtiest
4 Replies

2. UNIX for Dummies Questions & Answers

editor command

I want to copy lines say from 2-5 to line after 20 in vi editor. Can I achieve this in a single command in vi editor. Thanks. (2 Replies)
Discussion started by: tselvanin
2 Replies

3. UNIX for Dummies Questions & Answers

vim as command line editor

Here is my problem, I manage a SunOs 5.8 Server, vi is the default command line editor, I have a line on each users .kshrc profile as follows: export EDITOR=/bin/vi I want to use vim as the command line editor, the below line doesn't work export EDITOR=/bin/vim Thank you (1 Reply)
Discussion started by: tony3101
1 Replies

4. UNIX for Dummies Questions & Answers

Command to find out user creation date

Is there a Command to find out user creation date ? or any other possible ways to find the same. (6 Replies)
Discussion started by: Crazy_murli
6 Replies

5. UNIX for Dummies Questions & Answers

Search command on vi editor

Hi all, Here is an example, I would wan to search for all string consists of IMP but not IMP-00015. Values other than 00015 is fine, is there anyone knows how to do that? Thanks. (2 Replies)
Discussion started by: *Jess*
2 Replies

6. Shell Programming and Scripting

Easy ex editor command

I've this command in a script which edits the file ... bash$ cat temp_file.txt THREAD #2 2 Running bash$ (echo "s/THREAD #2/d"; echo 'wq') | ex -s temp_file.txt bash$ cat temp_file.txt THREAD #2 2 Running If i've more than 1 line it easily deletes the line, but if it is the last line... (3 Replies)
Discussion started by: prash184u
3 Replies

7. OS X (Apple)

How to get the file creation date with find command

Is it possible to find all files based on the date of creation? And if so, how? I've been looking at the find command but it seems that only modification times are used as an option. (1 Reply)
Discussion started by: Straitsfan
1 Replies

8. UNIX for Dummies Questions & Answers

Command to quit from vi editor

Hi Folks I have opened a log file in Vi editor vi abc.logPlease advise me how to finally quit from Vi editor, which command is there..! Is it :q<Enter> (1 Reply)
Discussion started by: KAREENA18
1 Replies

9. Shell Programming and Scripting

File creation using awk and gsub command

I have input file 04000912|100:|||||]|101:||]|creDate:1451876825000|1441324800000:]|1444003200000:]|1446595200000:]|1449187200000:]|1451865600000:] I have to get output as below ID|Re_Date|Re_Value|Re_date 04000912|100|40.0|44 04000912|100|50.0|55 04000912|100|60.0|66... (4 Replies)
Discussion started by: shabeena
4 Replies

10. UNIX for Beginners Questions & Answers

Accessing Isql command via VI editor

Hi Guru's, I'm new at Unix. I am tasked to monitor the filesystem utilization on OS level (Unix) and DB (Sybase) for multiple systems. I am thinking to use vi editor and make a file, execute that file and all the file systems I need to monitor will be be shown. My script inside vi goes in... (8 Replies)
Discussion started by: Xworks
8 Replies
BUFFCHAN(8)						      System Manager's Manual						       BUFFCHAN(8)

NAME
buffchan - buffered file-writing backend for InterNetNews SYNOPSIS
buffchan [ -b ] [ -c lines ] [ -C seconds ] [ -d directory ] [ -f fields ] [ -m map ] [ -p pidfile ] [ -l lines ] [ -L seconds ] [ -r ] [ -s file_format ] [ -u ] DESCRIPTION
Buffchan reads lines from standard input and copies certain fields in each line into files named by other fields within the line. Buffchan is intended to be called by innd(8) as an exploder feed. OPTIONS
-b Once buffchan opens a file it keeps it open. The input must therefore never specify more files than can the number of available descriptors can keep open. If the ``-b'' flag is used, the program will allocate a buffer and attach it to the file using set- buf(3). -c If the ``-c'' flag is used with a number n, then buffchan will close, and re-open, a file after every n lines are written to a file. -C Similarly, the ``-C'' flag may be used to specify that all files should be closed and re-opened every n seconds. -d The ``-d'' flag may be used to specify a directory the program should change to before starting. If this flag is used, then the default for the ``-s'' flag is changed to be a simple ``%s.'' -f Buffchan input is interpreted as a set of lines. Each line contains a fixed number of initial fields, followed by a variable number of filename fields. All fields in a line are separated by whitespace. The default number of initial fields is one; the ``-f'' flag may be used to specify a different number of fields. See filechan(8) for an example. -p If the ``-p'' flag is used, the program will write a line containing its process ID (in text) to the specified file. -l If the ``-l'' flag is used with a number n, then buffchan will call fflush(3) after every n lines are written to a file. -L If the ``-L'' flag is used with a number n, then all files will be flushed every n seconds. -r By default, the program sets its standard error to /var/log/news/errlog. To suppress this redirection, use the ``-r'' flag. -s After the initial fields, each remaining field names a file to write. The ``-s'' flag may be used to specify a format string that maps the field to a file name. This is a sprintf(3) format string which should have a single ``%s'' parameter which will be given the field. The default value is /var/spool/news/out.going/%s. See the description of this flag in filechan(8). -u If the ``-u'' flag is used, the program will request unbuffered output. Buffchan can be invoked as an exploder feed (see newsfeeds(5)). As such, if a line starts with an exclamation point it will be treated as a command. There are three commands, described below: flush The ``flush'' command closes and re-opens all open files; ``flush xxx'' which flushes only the specified site. These are analogous to the ctlinnd(8) ``flush'' command, and can be achieved by doing a ``send "flush xxx"'' command. Applications can tell that the ``flush'' has completed by renaming the file before issuing the command; buffchan has completed the command when the original file- name re-appears. Buffchan also changes the access permissions of the file from read-only for everyone to read-write for owner and group as it flushes or closes each output file. It will change the modes back to read-only if it re-opens the same file. drop The ``drop'' command is similar to the ``flush'' command except that any files are not re-opened. If given an argument, then the specified site is dropped, otherwise all sites are dropped. (Note that the site will be restarted if the input stream mentions the site.) When a ctlinnd ``drop site'' command is sent, innd will automatically forward the command to buffchan if the site is a fun- nel that feeds into this exploder. To drop all sites, use the ctlinnd ``send buffchan-site drop'' command. readmap The map file (specified with the ``-m'' flag) is reloaded. HISTORY
Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews. This is revision 1.11, dated 1996/10/29. SEE ALSO
ctlinnd(8), filechan(8), innd(8), newsfeeds(5). BUFFCHAN(8)
All times are GMT -4. The time now is 08:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy