Sponsored Content
Top Forums Shell Programming and Scripting How to sort lines according words? Post 302885729 by RudiC on Tuesday 28th of January 2014 06:40:07 AM
Old 01-28-2014
It's not that easy - need to use a "_" to preserve the TAB in the first column. Not sure how to overcome that behaviour.
Code:
awk     '$1!~/^NAME/    {$1="_\t"$1; $0=$0}
         $2!~/^ADDR/    {$2="_\t"$2; $0=$0}
         $3!~/^NUMB/    {$3="_\t"$3; $0=$0}
         1
        ' file
NAME="Adel" ADDRESS="Donaustr." NUMBER="2" POSTCODE="33333"
NAME="Adel" ADDRESS="Donaustr." NUMBER="2" POSTCODE="33333"
NAME="Adel" _     NUMBER="2" POSTCODE="33333"
NAME="Adel" ADDRESS="Donaustr." _     POSTCODE="33333"
NAME="Adel" ADDRESS="Donaustr." NUMBER="2" POSTCODE="33333"
_     ADDRESS="Donaustr." NUMBER="2" POSTCODE="33333"

---------- Post updated at 12:40 ---------- Previous update was at 12:29 ----------

Or
Code:
awk     'BEGIN          {n=split ("NAME ADDR NUMB POST", TAG)}
         NF != n        {for (i=0; i<=NF; i++) if ($(NF-i) !~ "^"TAG[n-i]) $(NF+1-i)="\t"$(NF+1-i++)}
         1
        ' file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete lines that contain 3 or more words?

How can I delete lines that contain 3 or more words? I have a file, old.txt, that has multi-word phrases in it and I want to remove the lines with 3 words or more and send the output to new.txt. I've tried the following using sed but it doesn't seem to work: sed '/(\b\w+\b){3,}/d' old.txt >... (5 Replies)
Discussion started by: revax
5 Replies

2. Shell Programming and Scripting

sort words in a line

Hi Im looking for a way, hopefully a one-liner to sort words in a line e.g "these are the words in a line" to "a are in line the these words" Thanks! (15 Replies)
Discussion started by: rebelbuttmunch
15 Replies

3. Shell Programming and Scripting

Count the no of lines between two words

Please help in the following problem: Input is: Pritam 123 456 Patil myname youname Pritam myproject thisproject iclic Patil remaining text some more text I need the command which will display the no of lines between two words in the whole file. e.g. Display all the no of lines... (5 Replies)
Discussion started by: zsudarshan
5 Replies

4. Shell Programming and Scripting

Keep lines with specific words up in an order

I hava a file with following data: number|CREDIT_ID|NULL date|SYS_CREATION_DATE|NULL varchar2|GGS_COMMIT_CHAR|NULL varchar2|GGS_OP_TYPE|NULL number|GGS_SCN|NULL| number|GGS_LOG_SEQ|NULL number|GGS_LOG_POS|NULL number|GGS_ORACREC_SCN|NULL varchar2|BATCH_ID|NULL char|GGS_IMAGE_TYPE|NULL ... (6 Replies)
Discussion started by: kolesunil
6 Replies

5. UNIX for Dummies Questions & Answers

Trying to sort words and numbers associated with them.

Hi. I have a file containing words and numbers associated with them as follows - c 2 b 5 c 5 b 6 a 10 b 16 c 18 a 19 b 21 c 27 a 28 b 33 a 76 a 115 c 199 c 251 a 567 a 1909 (4 Replies)
Discussion started by: maq
4 Replies

6. UNIX for Dummies Questions & Answers

words sort

hello guys i need a command that take the words from multiple files and put them in another file this way: one word needs to appear only once in the destination file with small letters no matter how it appears in source files , the words from destination file needs to be alphabetical ordered and... (10 Replies)
Discussion started by: G30
10 Replies

7. UNIX for Dummies Questions & Answers

Extract lines with specific words with addition 2 lines before and after

Dear all, Greetings. I would like to ask for your help to extract lines with specific words in addition 2 lines before and after these lines by using awk or sed. For example, the input file is: 1 ak1 abc1.0 1 ak2 abc1.0 1 ak3 abc1.0 1 ak4 abc1.0 1 ak5 abc1.1 1 ak6 abc1.1 1 ak7... (7 Replies)
Discussion started by: Amanda Low
7 Replies

8. Shell Programming and Scripting

How can I sort by n number is like words?

I want to sort a file with a list of words, in order of most occuring words to least occurring words as well as alphabetically. ex: file1: cat 3 cat 7 cat 1 dog 3 dog 5 dog 9 dog 1 ape 4 ape 2 I want the outcome to be: file1.sorted: dog 1 (12 Replies)
Discussion started by: castrojc
12 Replies

9. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

10. UNIX for Advanced & Expert Users

Sort words based on word count on each line

Hi Folks :) I have a .txt file with thousands of words. I'm trying to sort the lines in order based on number of words per line. Example from: word word word word word word word word word word word word word word word word to desired output: word (2 Replies)
Discussion started by: martinsmith
2 Replies
OCI_NUM_FIELDS(3)														 OCI_NUM_FIELDS(3)

oci_num_fields - Returns the number of result columns in a statement

SYNOPSIS
int oci_num_fields (resource $statement) DESCRIPTION
Gets the number of columns in the given $statement. PARAMETERS
o $statement - A valid OCI statement identifier. RETURN VALUES
Returns the number of columns as an integer, or FALSE on errors. EXAMPLES
Example #1 oci_num_fields(3) example <?php // Create the table with: // CREATE TABLE mytab (id NUMBER, quantity NUMBER); $conn = oci_connect("hr", "hrpwd", "localhost/XE"); if (!$conn) { $m = oci_error(); trigger_error(htmlentities($m['message']), E_USER_ERROR); } $stid = oci_parse($conn, "SELECT * FROM mytab"); oci_execute($stid, OCI_DESCRIBE_ONLY); // Use OCI_DESCRIBE_ONLY if not fetching rows $ncols = oci_num_fields($stid); for ($i = 1; $i <= $ncols; $i++) { echo oci_field_name($stid, $i) . " " . oci_field_type($stid, $i) . "<br> "; } // Outputs: // ID NUMBER // QUANTITY NUMBER oci_free_statement($stid); oci_close($conn); ?> NOTES
Note In PHP versions before 5.0.0 you must use ocinumcols(3) instead. This name still can be used, it was left as alias of oci_num_fields(3) for downwards compatability. This, however, is deprecated and not recommended. PHP Documentation Group OCI_NUM_FIELDS(3)
All times are GMT -4. The time now is 04:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy