Sponsored Content
Top Forums Shell Programming and Scripting Reversing large data set with awk? Post 303010497 by Mothra on Tuesday 2nd of January 2018 10:56:09 AM
Old 01-02-2018
Thank you so much for your reply! Also happy new year!
I am attempting to get this particular line of code to work but every time I run it with Command Prompt (after installing awk on this machine) it spits out a blank file. I have name script "nodesTwo" and in command prompt (in order to invoke the script) I am typing the following (Where ShapeData.txt is the file I am running the script on and ShapeDataFixed.txt is the intended output file)

Code:
awk nodesTwo ShapeData.txt>ShapeDataFixed.txt

Also!
In the line of code that you so kindly provided, there is an 'f' following the word 'print' just before RS}'
Was this a typo or is this required? is this telling the script to print file?
Thanks again! Your knowledge and experience is very much appreciated Smilie

I also tried to place ShapeData.txt>ShapeDataFixed.txt into the awk script itself and run the script but the command prompt just hangs and seems to be doing nothing...
Your beautiful example in practice (EXSmilie

Code:
awk '{for(i=1; i<=6; i++) print $i; for(i=NF-2; i>=7; i-=3) print $i, $(i+1), $(i+2); printf RS}' ORS=" " ShapeData.txt>ShapeDataFixed.txt

When I attempt to run this entire line (instead of just invoking the script inside the command prompt, I am given a (the system cannot find the file specified) despite it being inside the same directory of the currently executing script?
So sorry for the basic vibes I'm giving off! I've never used awk before this!
So any and all help is so so appreciated Smilie Thank you for your time and patience!

---------- Post updated at 08:56 AM ---------- Previous update was at 08:53 AM ----------

Quote:
Originally Posted by ctac_
You can use sed too.
If the data don't contain _
Code:
sed 's/(/_/g;:A;s/\([^_]*\)\(.*\)_\([^_]*\)/\1(\3 \2/;tA;s/  / /g;s/  / /g;s/ $//' infile

This is excellent! So appreciative to have another approach to this issue Linux Thank you for your suggestion and example! Both are gorgeous!
I try and run the script on a specific file in the directory of the executing script and it is giving me a "line 2: unterminated 's' command" I'm having trouble locating where the particular s command is! so many /'s and \'s!

Also!
Maybe I am not executing the script correctly? I hope I am!
I am running it with

sed -f nodes.sed

where 'nodes.sed' is the name of the file I would like the script to execute on (this file is in the same directory as the script)
Any and all help is appreciated!

Last edited by Scrutinizer; 01-02-2018 at 01:00 PM.. Reason: A different approach!; [mod] code tags
 

9 More Discussions You Might Find Interesting

1. HP-UX

large file options is set

Can someone tell me the right or exact syntax to check if the large file options is set on a filesystem Thanks! (2 Replies)
Discussion started by: catwomen
2 Replies

2. Shell Programming and Scripting

awk and reversing

Hello I'm writing script in awk that reverse order the fields of every line in file. My script have problem with spaces - if there is more spaces between fields in line of file - my script erase them . I want my script work like command "tac" - how to change it ? #!/bin/sh file=$1... (1 Reply)
Discussion started by: scotty_123
1 Replies

3. Shell Programming and Scripting

Drop common lines at head/tail of a large set of files

Hi! I have a large set of pairs of text files (each pair in their own subdirectory) and each pair shares head/tail (a couple of first and last lines) but differs in the middle part. I need to delete the heads/tails and keep only the middle portions in which they differ. The lengths of heads/tails... (1 Reply)
Discussion started by: dobryden
1 Replies

4. Shell Programming and Scripting

reversing and appending data in multiple files

Hello, I have a some files that look like this: 0 3 1 5 2 8 3 7 I want to reverse and append the data so it looks like this: 3 7 2 8 1 5 0 3 0 3 1 5 2 8 3 7 I first thought about using cat and tac cleverly with some redirection and pipe in a one-liner but I couldn't get it to... (1 Reply)
Discussion started by: bigfoot
1 Replies

5. Shell Programming and Scripting

Using AWK to separate data from a large XML file into multiple files

I have a 500 MB XML file from a FileMaker database export, it's formatted horribly (no line breaks at all). The node structure is basically <FMPXMLRESULT> <METADATA> <FIELD att="............." id="..."/> </METADATA> <RESULTSET FOUND="1763457"> <ROW att="....." etc="...."> ... (16 Replies)
Discussion started by: JRy
16 Replies

6. UNIX for Dummies Questions & Answers

Reversing line and word order using awk

Hello, I am new to awk and I was wandering if I could reverse line and word order from a text file using awk. I figured out how to do them both separately, but can't quite figure out how to mix them. Example: Input file: dog cat mouse 1 2 3 I am new to awk Output of the awk program:... (3 Replies)
Discussion started by: blink_w
3 Replies

7. Shell Programming and Scripting

awk : Filter a set of data to parse header line and last field of multiple same match.

Hi Experts, I have a data with multiple entry , I want to filter PKG= & the last column "00060110" or "00088150" in the output file: ############################################################################################### PKG= P8SDB :: VGS = vgP8SOra vgP8SDB1 vgP8S001... (5 Replies)
Discussion started by: rveri
5 Replies

8. Programming

C++ help in large data set

Hi All, We are trying to replace a 3rdparty where we don't know how they handled the reader part here. The query below is getting 197 * 2038017 row in the table. In the below code we are trying to run the query and execute in the DB part and fetch and read the record. That is where it is... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

9. Shell Programming and Scripting

How to make awk command faster for large amount of data?

I have nginx web server logs with all requests that were made and I'm filtering them by date and time. Each line has the following structure: 127.0.0.1 - xyz.com GET 123.ts HTTP/1.1 (200) 0.000 s 3182 CoreMedia/1.0.0.15F79 (iPhone; U; CPU OS 11_4 like Mac OS X; pt_br) These text files are... (21 Replies)
Discussion started by: brenoasrm
21 Replies
All times are GMT -4. The time now is 02:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy