- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Sorting on fixed width file
- Labels:
-
Apache NiFi
Created ‎12-03-2024 09:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Team,
how to sort this below output in Ascending order by maintaining same space in both header values. I've tried using query record but couldn't able to add spaces using SPACE function. but space which i've given is considering as SPACE(numeric) value instead of INT.
input:
NO CUSTOM.;NO INCSUPB;NO ALLBPBM ;IMPORTE BRUTO;DESCUENTO;IMPORTE NETO
0000000023;123548 ;999888 ;875,92 ;176,88 ;699,04
0000000012;123547 ;777666 ;2347,04 ;591,84 ;1755,2
Expected Output:
NO CUSTOM.;NO INCSUPB;NO ALLBPBM ;IMPORTE BRUTO;DESCUENTO;IMPORTE NETO
0000000012;123547 ;777666 ;2347,04 ;591,84 ;1755,2
0000000023;123548 ;999888 ;875,92 ;176,88 ;699,04
Created on ‎01-20-2025 02:20 AM - edited ‎01-20-2025 02:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#!/bin/bash
# Input data
input_file="input.txt"
# Separate the header and the data
header=$(head -n 1 "$input_file")
data=$(tail -n +2 "$input_file")
# Sort the data numerically by the first column
sorted_data=$(echo "$data" | sort -t';' -k1,1n)
# Combine the header with the sorted data
echo "$header"
echo "$sorted_data"
