How to append data in a PS file? - mainframe

I have the following line in a PS file
version
!cd "//''"
the another file contains the following line
remove
I want to append data from another file in between the single quotes of the above line. After Appending the characters(remove) from another the ps file should contain the following data
version
!cd "/remove/''"
I tried using OUTREC but it din work, the characters versions also got changed
SORT FIELDS=COPY
OUTREC FIELDS=(1:C'!cd "/',
6:1,6,
12:C''"')

Your FIELDS (which is better as BUILD) should be conditional to avoid processing every line.
You've not mentioned how you are getting the data from the other file.
Best would be two steps. Step 1, to create a "symbol file" (SYMNAMES DD when it is used in the second step) to take the data from your second file and give it a name.
Then in the second step, with conditional processing (IFTHEN=(WHEN=(logicalexpression)) to use the value of the symbol as the insertion.
I'm assuming your second file can sometimes contain different values? If not, why not just generate the whole thing? Or use your editor?

Related

How to check if a file is empty in VERILOG?

I would like to know how can I check if a file is empty in a VERILOG or SYSTEMVERILOG testbench.
I have 2 ideas:
Check the file size using $system() task, and put there a linux command which can tell the number of bits or bytes.
Read the first line using $fgets. If the line equal to 0, it means it's empty.
About the first method, I couldn't get a linux command which tells me just the number. I've tried for example ls -l and wc -c, but they give me much more than the number of bits.
About the second method, I really don't know how to read a specific line, in this case, it would be the first line of the file.
Assuming you've already checked the result from $fopen to see if the file exists, you can use $getc or $gets an see if it returns a code less than 1. But the best option depends on what you plan to do with the file after finding it empty or non empty.

How to remove \r\n line breaks in a text file that are within quotes and not the end of the row

I have a large set of files that contain line breaks within a column that are all wrapped in quotes, but U-SQL cannot process the files because it is seeing the \r\n as the end of the row despite being wrapped in quotes.
Is there an easy way to fix these files other than opening each file up individually in something like notepad++? It seems there should be a way to ignore line breaks if they are contained within quotes.
Example is something like this:
1,200,400,"123 street","123 street,\r\nNew York, NY\r\nUnited States",\N,\N,200\r\n
Notepad++ works fine for finding and replacing values manually, but I'm trying to find a batch way to do this because I have multiple files (50+ per source table) and hundreds of thousands of records in each that I need to fix.
According to U-SQL GitHub issue 84: USQL and embedded newline characters you can either build a custom extractor, or try to use the escapeCharacter parameter of the built-in extractor:
USING Extractors.Csv(quoting : true, escapeCharacter : '\\') // quoting is true by default, but it does not hurt to repeat.

copy and append specific lines to a file with specific name format?

I am copying some specific lines from one file to another.
grep '^stringmatch' /path/sfile-*.cfg >> /path/nfile-*.cfg
Here what's happening: its creating a new file called nfile-*.cfg and copying those lines in that. The file names sfile- * and nfile- * are randomly generated and are generally followed by a number. Both sfile-* and nfile-* are existing files and there is only one such file in the same directory. Only the number that follows is randomly generated. The numbers following in sfile and nfile need not be same. The files are not created simultaneously but are generated when a specific command is given. But some lines from one file to the another file needs to be appended.
I'm guessing you actually want something like
for f in /path/sfile-*.cfg; do
grep '^stringmatch' "$f" >"/path/nfile-${f#/path/sfile-}"
done
This will loop over all sfile matches and create an nfile target file with the same number after the dash as the corresponding source sfile. (The parameter substitution ${variable#prefix} returns the value of variable with any leading match on the pattern prefix removed.)
If there is only one matching file, the loop will only run once. If there are no matches on the wildcard, the loop will still run once unless you enable nullglob, which changes the shell's globbing behavior so that wildcards with no matches expand into nothing, instead of to the wildcard expression itself. If you don't want to enable nullglob, a common workaround is to add this inside the loop, before the grep;
test -e "$f" || break
If you want the loop to only process the first match if there are several, add break on a line by itself before the done.
If I interpret your question correctly, you want to output to an existing nfile, which has a random number in it, but instead the shell is creating a file with an asterisk in it, so literally nfile-*.cfg.
This is happening because the nfile doesn't exist when you first run the command. If the file doesn't exist, bash will fail to expand nfile-*.cfg and will instead use the * as a literal character. This is correct behaviour in bash.
So, it looks like the problem is that the nfile doesn't exist when you start your grep. You'll need to create one.
I'll leave code to others, but I hope the explanation is useful.

Saving a flat-file through Vim add an invisible byte to the file that creates a new line

The title is not really specific, but I have trouble identifying the correct key words as I'm not sure what is going on here. For the same reason, it is possible that my question has a duplicate, as . If that's the case: sorry!
I have a Linux application that receive data via flat files. I don't know exactly how those files are generated, but I can read them without any problem. Those are short files, only a line each.
For test purpose, I tried to modify one of those files and reinjected it again in the application. But when I do that I can see in the log that it added a mysterious page break at the end of the message (resulting in the application not recognising the message)...
For the sake of example, let's say I receive a flat file, named original, that contains the following:
ABCDEF
I make a copy of this file and named it copy.
If I compare those two files using the "diff" command, it says they are identical (as I expect them to be)
If I open copy via Vi and then quit without changing nor saving anything and then use the "diff" command, it says they are identical (as I also expect them to be)
If I open copy via Vi and then save it without changing anything and then use the "diff" command, I have the following (I added the dot for layout purpose):
diff original copy
1c1
< ABCDEF
\ No newline at end of file
---
.> ABCDEF
And if I compare the size of my two files, I can see that original is 71 bytes when copy is 72.
It seems that the format of the file change when I save the file. I first thought of an encoding problem, so I used the ":set list" command on Vim to see the invisible characters. But for both files, I can see the following:
ABCDEF$
I have found other ways to do my test, But this problem still bugged me and I would really like to understand it. So, my two questions are:
What is happening here?
How can I modify a file like that without creating this mysterious page break?
Thank you for your help!
What happens is that Vim is set by default to assume that the files you edit end with a "newline" character. That's normal behavior in UNIX-land. But the "files" your program is reading look more like "streams" to me because they don't end with a newline character.
To ensure that those "files" are written without a newline character, set the following options before writing:
:set binary noeol
See :help 'eol'.

Bash Scripting: Find strings on one line of code and insert on own line

I'm trying to write a small bash script that:
-wget's an html file every [x] minutes from the web
-uses some linux utility to find differences in the file between the last two updates
-Uses sed to modify the lines on which new text was detected
The problem I am running into is that the HTML file uses in-line CSS
to format a table, but the actual code for the page is stored on one long line.
Effectively I need a Linux utility that can scan through a single line of code, find
every instance of text between each tags, and insert those instances on their own line. That should make scanning the text easier. Every tool I've tried searches on a per-line basis which can't do what I need since the entire code is stored on a single line.
You could first split the content into lines, by substituting (say) > with >\n. That will break up the document on the end of each HTML tag.
Maybe you don't even need to do that: if you use awk's RS variable to define the record separator as ">" instead of newline. See this page for an example of using RS: http://www.thegeekstuff.com/2010/01/8-powerful-awk-built-in-variables-fs-ofs-rs-ors-nr-nf-filename-fnr/

Resources